如何阻止滚动更改事件触发数据绑定(WPF)
How to stop Scroll changed event from triggering on data binding (WPF)
</ItemsControl.ItemTemplate>
<ItemsControl.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" HorizontalAlignment="Center" FontWeight="Bold" Foreground="{StaticResource Accent}" Text="{Binding Path=Name , StringFormat={}{0:D}}" />
<ItemsPresenter Grid.Row="1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ItemsControl.GroupStyle>
</ItemsControl>
<Interactivity:Interaction.Triggers>
<Interactivity:EventTrigger EventName="ScrollChanged" >
<Presentation:InvokeDelegateCommandAction Command="{Binding ChatScrollViewer_OnViewChange}" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=InvokeParameter}" />
</Interactivity:EventTrigger>
</Interactivity:Interaction.Triggers>
</ScrollViewer>
private void ChatScrollViewer_OnViewChangeEvent(ScrollChangedEventArgs Event)
{
ScrollViewer scrollViewer = Event.OriginalSource as ScrollViewer;
if (scrollViewer.VerticalOffset == 0)
{
}
}
When data binding take place scroll changed event is triggered . How check that this is a trigger from data binding and do nothing and when triggered manually do something
绑定更新时,是滚动查看器的ItemsSource吗?
绑定可能会添加或删除某些内容,从而导致滚动查看器更改其内容的大小。看看the scroll changed event args,触发这个事件的条件很多。
您可能只想检查事件属性,例如:
VerticalChange - 获取指示 ScrollViewer 垂直偏移变化的值。
因此,请尝试仅在 VerticalChange != 0 时执行您的操作。或者在其中放置一个调试器,看看是否有您想要忽略的特定事件类型,这些事件类型仅在绑定更改时发生,例如:
ExtentHeightChange - 获取指示 ScrollViewerextent 高度变化的值。
绑定更新时可能只有 none-0,使滚动条变大(但不改变滚动位置)。
所以像这样:
private void ChatScrollViewer_OnViewChangeEvent(ScrollChangedEventArgs Event)
{
if (Event.VerticalChange != 0)
{
ScrollViewer scrollViewer = Event.OriginalSource as ScrollViewer;
if (scrollViewer.VerticalOffset == 0)
{
}
}
}
希望对您有所帮助。
</ItemsControl.ItemTemplate>
<ItemsControl.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" HorizontalAlignment="Center" FontWeight="Bold" Foreground="{StaticResource Accent}" Text="{Binding Path=Name , StringFormat={}{0:D}}" />
<ItemsPresenter Grid.Row="1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ItemsControl.GroupStyle>
</ItemsControl>
<Interactivity:Interaction.Triggers>
<Interactivity:EventTrigger EventName="ScrollChanged" >
<Presentation:InvokeDelegateCommandAction Command="{Binding ChatScrollViewer_OnViewChange}" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=InvokeParameter}" />
</Interactivity:EventTrigger>
</Interactivity:Interaction.Triggers>
</ScrollViewer>
private void ChatScrollViewer_OnViewChangeEvent(ScrollChangedEventArgs Event)
{
ScrollViewer scrollViewer = Event.OriginalSource as ScrollViewer;
if (scrollViewer.VerticalOffset == 0)
{
}
}
When data binding take place scroll changed event is triggered . How check that this is a trigger from data binding and do nothing and when triggered manually do something
绑定更新时,是滚动查看器的ItemsSource吗?
绑定可能会添加或删除某些内容,从而导致滚动查看器更改其内容的大小。看看the scroll changed event args,触发这个事件的条件很多。
您可能只想检查事件属性,例如:
VerticalChange - 获取指示 ScrollViewer 垂直偏移变化的值。
因此,请尝试仅在 VerticalChange != 0 时执行您的操作。或者在其中放置一个调试器,看看是否有您想要忽略的特定事件类型,这些事件类型仅在绑定更改时发生,例如:
ExtentHeightChange - 获取指示 ScrollViewerextent 高度变化的值。
绑定更新时可能只有 none-0,使滚动条变大(但不改变滚动位置)。
所以像这样:
private void ChatScrollViewer_OnViewChangeEvent(ScrollChangedEventArgs Event)
{
if (Event.VerticalChange != 0)
{
ScrollViewer scrollViewer = Event.OriginalSource as ScrollViewer;
if (scrollViewer.VerticalOffset == 0)
{
}
}
}
希望对您有所帮助。