質問

拡張器のグループが入ったスタックパネルを持っていますが、一度にエキスパンダーだけが拡張されるように設定するにはどうすればよいですか?

乾杯

ああ

役に立ちましたか?

解決

ウィンドウのファイルの後ろのクラスにコード(C#)を入力する必要があるため、このようにやりたくありませんでした(ビューモデルなどを完全に避けようとしています)。

理想的には、これをXAMLで説明していたでしょう。

私は興味のあるすべてのエキスパンダー「拡張」イベントに接続し、次のことをしました。

    private void HandleExpanderExpanded(object sender, RoutedEventArgs e)
    {
        ExpandExculsively(sender as Expander);
    }

    private void ExpandExculsively(Expander expander)
    {
        foreach (var child in findPanel.Children)
        {
            if (child is Expander && child != expander)
                ((Expander)child).IsExpanded = false;
        }
    }

乾杯

AWC

他のヒント

「拡張されたエキスパンダー」である値を持つ依存関係プロパティを追加できます。その後、「拡張された」プロパティを式に「ExpandedProperty ==」にバインドできます。

背後にコードなしでWPFでそれを行うためのより精巧な方法を以下に示します。

<UserControl.Resources>
    <ResourceDictionary>
        ...
        <Style TargetType="{x:Type Expander}">
            <Setter Property="IsExpanded" Value="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"/>
        </Style>

    </ResourceDictionary>

</UserControl.Resources>

<Grid x:Name="LayoutRoot" Background="{x:Null}" Margin="10">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <ScrollViewer VerticalAlignment="Top" HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Auto" VerticalContentAlignment="Top" BorderThickness="0,0,0,0" Grid.RowSpan="1" Grid.Row="0">
        <ListBox x:Name="OrdersListBox" BorderThickness="0" ItemContainerStyle="{StaticResource ShellThemeListBoxStyle}" 
                 IsSynchronizedWithCurrentItem="True" 
                 prism:RegionManager.RegionName="{x:Static uiCommon:RegionNames.WorkSheetsRegion}" Background="#00000000">
            <ListBox.ItemTemplate>
                <DataTemplate DataType="typeData:WorkSheetsDetialsViewModel">
                    <local:WorkSheetsDetialsView/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </ScrollViewer>
    ...
</Grid>

<UserControl 
    x:Class="Module.ExcelDocumentManager.WorkSheets.WorkSheetsDetialsView"
    ...>
    <Expander>
        <Expander.Header>
            <TextBlock Text="{Binding HeaderInfo}" RenderTransformOrigin=".5,.5">
            </TextBlock>
        </Expander.Header>
        ...

    </Expander>
</UserControl>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top