Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF DependencyProperty Firing only once
    primarykey
    data
    text
    <p>I am having issues with one of my dependency properties not firing on change. Set up is as follows. I have a class that acts as a mediator for a ScrollViewer, in there I have a dependency property for a ScrollViewer type, and 2 doubles, VerticalOffsetNew, and VerticalScrollOffset. So I attach a previewmousewheel event to grab events coming from the mouse wheel.</p> <p>In this event i grab the scrollviewers current offset and set VerticalScrollOffset to that value. Then depending on the delta I set the VerticalOffsetNew to be offset+delta.</p> <p>Now the issue I am seeing is the following. the VerticalScrollOffset does not seem to get set after the first time. I have a onpropertychange event for that and the breakpoint is only hit the first time. The other property that is being set in the preview event (verticaloffsetnew) gets set everytime no problem.</p> <p>any ideas?</p> <pre><code>public double VerticalScrollOffset { get { return (double)GetValue(VerticalScrollOffsetProperty); } set { SetValue(VerticalScrollOffsetProperty, value); } } public static readonly DependencyProperty VerticalScrollOffsetProperty = DependencyProperty.Register("VerticalScrollOffset", typeof(double), typeof(ScrollViewerOffsetMediator), new PropertyMetadata(OnVerticalScrollOffsetChanged)); public static void OnVerticalScrollOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ScrollViewerOffsetMediator mediator = (ScrollViewerOffsetMediator)d; } </code></pre> <p>Above is my DP that is only set once in the preview code, below is the preview code.</p> <pre><code>private void CustomPreviewMouseWheel(object sender, MouseWheelEventArgs e) { double mouseWheelChange = (double)e.Delta; ScrollViewer thisScroller = (ScrollViewer)sender; // not sure why the delta is so large here //double newVOffset = this.VerticalOffset - (mouseWheelChange / 40); // forcing scroll wheel to iterate by 8 mouseWheelChange /= Math.Abs(mouseWheelChange); double newVOffset = thisScroller.VerticalOffset - (mouseWheelChange * 8); // this does not trigger a change after the first time for some // some strange reason !!!!!!! this.VerticalScrollOffset = thisScroller.VerticalOffset; if (newVOffset &lt; 0) { this.VerticalOffset = 0; } else if (newVOffset &gt; thisScroller.ScrollableHeight) { this.VerticalOffset = thisScroller.ScrollableHeight; } else { this.VerticalOffset = newVOffset; } e.Handled = true; } </code></pre> <p>Thanks for any help.</p> <p><strong>Update</strong></p> <p>So there is something else I have noticed, the preview mouse call updates both the VerticalOffset and the VerticalScrollOffset. Both of which are DP's, now the thing that is interesting is that in the change event of the VerticalOffset there is a call to an animate method that will animate the VerticalScrollOffset DP. It seems that when I remove that call both DP's change correctly but as soon as I have that it fails. Is there some restriction or conflicts that may be arising, that I dont see or WPF silently tries to resolve?</p> <p>Thanks again.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload