在 Avalonia 的 ControlTemplate 中引发水平滚动更改事件时如何绑定 2 个 ScrollViewer 控件?
How to bind 2 ScrollViewer controls when horizontal scroll change event is raised in a ControlTemplate in Avalonia?
我正在制作自定义 table 控件。它有 2 个滚动查看器,一个用于行部分,另一个隐藏在列部分中。它们都位于 DataTemplate 中。当用户水平滚动行部分时,我想水平滚动列部分。我尝试将 Offset 属性 绑定到彼此,但不知道如何仅对 X 轴执行此操作。这在 xaml 端是否可能,还是必须在 C# 中发生?两种方式都可以,只是想弄清楚如何去做。
Avalonia's Github 那边有人回答了。我会在这里分享。我想多了。您可以只绑定整个 Offset 对象。
<StackPanel Spacing="5">
<ScrollViewer x:Name="ScrollViewer1" HorizontalScrollBarVisibility="Visible" Height="50">
<Border MinWidth = "2000" Background="{DynamicResource SystemAccentColor}">
<TextBlock>This is a very very long Text in ScrollViewer 1. This is a very very long Text in ScrollViewer 1. This is a very very long Text in ScrollViewer 1. This is a very very long Text in ScrollViewer 1. </TextBlock>
</Border>
</ScrollViewer>
<ScrollViewer x:Name="ScrollViewer2" HorizontalScrollBarVisibility="Visible" Height="50"
Offset="{Binding #ScrollViewer1.Offset, Mode=TwoWay}">
<Border MinWidth = "2000" Background="{DynamicResource SystemAccentColorDark2}">
<TextBlock>This is a very very long Text in ScrollViewer 2. This is a very very long Text in ScrollViewer 2. This is a very very long Text in ScrollViewer 2. This is a very very long Text in ScrollViewer 2. </TextBlock>
</Border>
</ScrollViewer>
</StackPanel>
我正在制作自定义 table 控件。它有 2 个滚动查看器,一个用于行部分,另一个隐藏在列部分中。它们都位于 DataTemplate 中。当用户水平滚动行部分时,我想水平滚动列部分。我尝试将 Offset 属性 绑定到彼此,但不知道如何仅对 X 轴执行此操作。这在 xaml 端是否可能,还是必须在 C# 中发生?两种方式都可以,只是想弄清楚如何去做。
Avalonia's Github 那边有人回答了。我会在这里分享。我想多了。您可以只绑定整个 Offset 对象。
<StackPanel Spacing="5">
<ScrollViewer x:Name="ScrollViewer1" HorizontalScrollBarVisibility="Visible" Height="50">
<Border MinWidth = "2000" Background="{DynamicResource SystemAccentColor}">
<TextBlock>This is a very very long Text in ScrollViewer 1. This is a very very long Text in ScrollViewer 1. This is a very very long Text in ScrollViewer 1. This is a very very long Text in ScrollViewer 1. </TextBlock>
</Border>
</ScrollViewer>
<ScrollViewer x:Name="ScrollViewer2" HorizontalScrollBarVisibility="Visible" Height="50"
Offset="{Binding #ScrollViewer1.Offset, Mode=TwoWay}">
<Border MinWidth = "2000" Background="{DynamicResource SystemAccentColorDark2}">
<TextBlock>This is a very very long Text in ScrollViewer 2. This is a very very long Text in ScrollViewer 2. This is a very very long Text in ScrollViewer 2. This is a very very long Text in ScrollViewer 2. </TextBlock>
</Border>
</ScrollViewer>
</StackPanel>