0
有一個自定義用戶控件ExpanderListUC,它包含擴展的列表中的每個擴展器具有包含標籤的列表一個StackPanel。我如何自動滾動的ScrollViewer到specefic位置
我添加了一個ScrollViewer中,並上下滾動通過擴展內容。
在某些情況下,我已經自動選擇標籤4膨脹機4通過後面的代碼。
我怎麼能自動ScrollViewer中的位置設置成選擇的標籤?
<ScrollViewer x:Name="sv" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" HorizontalAlignment="Left" Width="205">
<StackPanel Name="spContentPresenter" Background="Transparent" HorizontalAlignment="Right" >
<StackPanel.ContextMenu>
<ContextMenu x:Name ="ExpanderContextMenu" StaysOpen="true">
<MenuItem x:Name="collapseAllMenuItem" Header="Collapse All" Foreground="Black" />
<MenuItem x:Name="expandAllMenuItem" Header="Expand All" Foreground="Black" />
</ContextMenu>
</StackPanel.ContextMenu>
<Expander FlowDirection="LeftToRight" IsEnabled="True" IsExpanded="True" >
<!--Background="#FF1F5897"-->
<Expander.Header>
<!--<Run Text="Electrical Information" Foreground="Black"/>-->
<TextBlock HorizontalAlignment="Right" Foreground="Black"><Run Text="Expander 1"/></TextBlock>
</Expander.Header>
<Grid Margin="0" >
<StackPanel Width="200" HorizontalAlignment="Right">
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 1" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 2" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 3" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 4" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 5" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 6" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 7" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 8" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 9" Height="26" />
<!--Style="{DynamicResource ClickableLabel}"-->
</StackPanel>
</Grid>
</Expander>
<Expander FlowDirection="LeftToRight" IsEnabled="True" IsExpanded="True" >
<!--Background="#FF1F5897"-->
<Expander.Header>
<!--<Run Text="Electrical Information" Foreground="Black"/>-->
<TextBlock HorizontalAlignment="Right" Foreground="Black"><Run Text="Expander 2"/></TextBlock>
</Expander.Header>
<Grid Margin="0" >
<StackPanel Width="200" HorizontalAlignment="Right">
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 1" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 2" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 3" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 4" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 5" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 6" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 7" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 8" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 9" Height="26" />
<!--Style="{DynamicResource ClickableLabel}"-->
</StackPanel>
</Grid>
</Expander>
<Expander FlowDirection="LeftToRight" IsEnabled="True" IsExpanded="True" >
<!--Background="#FF1F5897"-->
<Expander.Header>
<!--<Run Text="Electrical Information" Foreground="Black"/>-->
<TextBlock HorizontalAlignment="Right" Foreground="Black"><Run Text="Expander 3"/></TextBlock>
</Expander.Header>
<Grid Margin="0" >
<StackPanel Width="200" HorizontalAlignment="Right">
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 1" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 2" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 3" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 4" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 5" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 6" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 7" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 8" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 9" Height="26" />
<!--Style="{DynamicResource ClickableLabel}"-->
</StackPanel>
</Grid>
</Expander>
<Expander FlowDirection="LeftToRight" IsEnabled="True" IsExpanded="True" >
<!--Background="#FF1F5897"-->
<Expander.Header>
<!--<Run Text="Electrical Information" Foreground="Black"/>-->
<TextBlock HorizontalAlignment="Right" Foreground="Black"><Run Text="Expander 4"/></TextBlock>
</Expander.Header>
<Grid Margin="0" >
<StackPanel Width="200" HorizontalAlignment="Right">
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 1" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 2" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 3" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 4" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 5" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 6" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 7" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 8" Height="26" />
<Label Margin="0,0,10,0" HorizontalAlignment="Right" Content="Label 9" Height="26" />
<!--Style="{DynamicResource ClickableLabel}"-->
</StackPanel>
</Grid>
</Expander>
</StackPanel>
</ScrollViewer>
我已經有擴展的獨立控制。 我試過你的代碼,並且提供的方法不起作用。 – Cracker