当突然用itemControl模板替换StackPanel时,滚动不再正常工作。
旧:
<ScrollViewer x:Name="HorizontalScroller"
Grid.Column="1"
VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Hidden"
CanContentScroll="True" Margin="2.4,0,1.2,0">
<StackPanel x:Name="spHorizontal" Orientation="Horizontal" UseLayoutRounding="False"
ScrollViewer.VerticalScrollBarVisibility="Disabled" Width="862.4"/>
</ScrollViewer>
新:
<ScrollViewer x:Name="HorizontalScroller" Grid.Column="1" VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Hidden" CanContentScroll="True" Margin="2.4,0,1.2,0" >
<!---RegBtns verwijst naar de ObservableCollection die alle registration buttons bevat-->
<ItemsControl Name="ItemControlRegistration" ItemsSource="{Binding ElementName=Window, Path=RegBtns}" Width="834.4">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel x:Name="spHorizontal" Orientation="Horizontal" UseLayoutRounding="False" ScrollViewer.VerticalScrollBarVisibility="Disabled"
Width="834,4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!--template custom style button: -->
<Button x:Name="RegistrationTestButton" Content="TEST" HorizontalAlignment="Left" Height="73" Width="151"
Margin="10,0,5,0" Style="{DynamicResource ButtonStyleRegistration}"
Click="RegistrationTestButton_Click">
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
问题是它没有完全显示按钮。意思是从1-5浏览并按右键不直接显示2-6。 换句话说,如果我按下右边我想立刻看到完整的按钮nr 6。现在它基本上向右(或左)缓慢滚动,按钮部分缓慢出现。 当我按下我希望立即显示下一个按钮。
究竟是什么造成了这些突然的变化?
问候。
答案 0 :(得分:0)
为什么不将scrollViewer放入ItemsControl的模板中?我的意思是......跟随
<ItemsControl Name="ItemControlRegistration" ItemsSource="{Binding ElementName=Window, Path=RegBtns}" Width="834.4">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<ScrollViewer x:Name="HorizontalScroller" Grid.Column="1" VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Hidden" CanContentScroll="True" Margin="2.4,0,1.2,0" >
<StackPanel x:Name="spHorizontal" Orientation="Horizontal" UseLayoutRounding="False" ScrollViewer.VerticalScrollBarVisibility="Disabled"
Width="834,4" />
</ScrollViewer>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!--template custom style button: -->
<Button x:Name="RegistrationTestButton" Content="TEST" HorizontalAlignment="Left" Height="73" Width="151"
Margin="10,0,5,0" Style="{DynamicResource ButtonStyleRegistration}"
Click="RegistrationTestButton_Click">
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>