我的ScrollViewer自动滚动到中间偏移,即使我试图强制它回到0偏移它仍然不正确对齐
以下是XAML的一部分:
<ScrollViewer x:Name="ScrollView" Grid.Row="0" Grid.Column="0" VerticalScrollBarVisibility="Auto">
<TreeView Grid.ColumnSpan="2" Name="LOBSummaryTree"
BorderThickness="0" DataContext="{Binding}">
<TreeView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
<common:VisibilityConverter x:Key="VisibilityConverter"/>
<common:TextStyleConverter x:Key="TextStyleConverter"/>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate DataType="ContentPresenter">
<StackPanel x:Name="StackGroups" Orientation="Horizontal">
<TextBlock Name="txtBox" Tag="{Binding}">
从后面的代码尝试强制抵消:
var scrollViewer = this.ScrollView;
if (scrollViewer != null)
{
scrollViewer.InvalidateScrollInfo();
scrollViewer.ScrollToHorizontalOffset(0);
UpdateLayout();
}
我做错了什么,我想在树视图的初始加载时将水平scollbar的对齐强制到左边?