0

カスタムユーザーコントロールExpanderListUCがあります。これには、エキスパンダーのリストが含まれています。各エキスパンダーには、ラベルのリストを含むスタックパネルがあります。

エキスパンダーのコンテンツを上下にスクロールするためのscrollviewerを追加しました。

場合によっては、コードビハインドを使用してエキスパンダー4のラベル4を自動的に選択する必要があります。

スクロールビューアの位置を選択したラベルに自動的に設定するにはどうすればよいですか?

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

1 に答える 1