gpt4 book ai didi

c# - 如何阻止滚动更改事件触发数据绑定(bind)(WPF)

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:03 25 4
gpt4 key购买 nike

                </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

最佳答案

绑定(bind)更新时,是滚动查看器的ItemsSource吗?

绑定(bind)可能会添加或删除某些内容,从而导致滚动查看器更改其内容的大小。看看the scroll changed event args , 触发此事件的条件很多。

您可能只想检查事件属性,例如:

VerticalChange - 获取一个值,该值指示 ScrollViewer 的垂直偏移量的变化。

因此,尝试仅在 VerticalChange != 0 时执行您的操作。或者在其中放置一个调试器,看看是否有任何您想要忽略的特定事件类型,这些事件类型仅在绑定(bind)更改时发生,例如:

ExtentHeightChange - 获取指示 ScrollViewerextent 高度变化的值。

当绑定(bind)更新时可能只有非零值,使滚动条变大(但不改变滚动位置)。

所以像这样:

private void ChatScrollViewer_OnViewChangeEvent(ScrollChangedEventArgs Event)
{
if (Event.VerticalChange != 0)
{
ScrollViewer scrollViewer = Event.OriginalSource as ScrollViewer;
if (scrollViewer.VerticalOffset == 0)
{

}
}
}

希望对您有所帮助。

关于c# - 如何阻止滚动更改事件触发数据绑定(bind)(WPF),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36497417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com