【问题标题】:Show collection of groupdescription from a list as source将列表中的组描述集合显示为源
【发布时间】:2016-07-26 11:17:12
【问题描述】:

对不起,误导性的标题。无论如何,我会尽力解释得更好。我想在 ListView 的集合中显示集合。但是显示器应该使用扩展器来显示内部集合项目。所有项目都应出现在相应的列中。其实我做的是这样的:

XAML

<CollectionViewSource x:Key="GroupedItems" Source="{Binding Countries}">
 <CollectionViewSource.GroupDescriptions>
     <PropertyGroupDescription PropertyName="Name"/>
 </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
...
<ListView ItemsSource="{Binding Source={StaticResource GroupedItems}}" Name="Playing">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Country" Width="150" DisplayMemberBinding="{Binding Source={x:Static sys:String.Empty}}" />
            <GridViewColumn Header="Leagues">                        
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <ItemsControl ItemsSource="{Binding Leagues}" Margin="25 0 0 0">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid HorizontalAlignment="Stretch" Background="#FFBCDAEC">
                                        <TextBlock FontSize="18" Padding="5" Text="{Binding Name}"/>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
    <ListView.GroupStyle>
        <GroupStyle>
            <GroupStyle.ContainerStyle>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Expander IsExpanded="True">
                                    <Expander.Header>
                                        <TextBlock Text="{Binding Name}" Foreground="Red" FontSize="22" VerticalAlignment="Bottom" />
                                    </Expander.Header>
                                    <ItemsPresenter />
                                </Expander>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </GroupStyle.ContainerStyle>
        </GroupStyle>
    </ListView.GroupStyle>
</ListView>

上面的代码在扩展器中显示了国家/地区的名称,但不幸的是,我无法将列表中的国家/地区名称显示为扩展器列表。

我也想显示联赛的扩展器,相应的比赛应该出现在相应的列中。在我的 ViewModel 中,我有一个 Country 集合,以及每个 Country&gt;Leagues collection &gt;Matches 集合。

查看以下课程:

public partial class WinExpander : Window
{
    public WinExpander()
    {
        InitializeComponent();

        this.DataContext = new ViewModel();
    }
} 

public class ViewModel
{
    public List<Country> Countries { get; set; }
    public ViewModel()
    {
        Countries = new List<Country>();
    }
}

public class Country
{
    public string Name { get; set; }
    public List<League> Leagues { get; set; }

    public Country()
    {
        Leagues = new List<League>();
    }
}

public class League
{
    public string Name { get; set; }
    public List<Match> Matches { get; set; }

    public League()
    {
        Matches = new List<Match>();
    }
}

public class Match
{
    public string Name { get; set; }
}

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    1. Expander 用于Matches。要将MatchesLeagues 同步显示,请同时同步Leagues Expander 和Matches Expander。当我们扩展League时,对应的Matches扩展器也会扩展。

    2. 为了获得正确的外观和感觉,我们必须从 Match 列中删除 Expander Icon

    3. 要同步 LeagueMatch Expanders,请在 League 中引入一个名为“IsExpanded”的属性。现在League 类必须实现INotifyPropertyChanged

      bool _isExpanded=true;
      public bool IsExpanded
      {
          get { return _isExpanded; }
          set { _isExpanded = value; OnPropertyChanged("IsExpanded"); }
      }
      

    列表视图标记:

    <ListView ItemsSource="{Binding Source={StaticResource GroupedItems}}" Name="Playing">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Country" Width="150" DisplayMemberBinding="{Binding Source={x:Static sys:String.Empty}}" />
                <GridViewColumn Header="Leagues">
                    <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <ItemsControl Margin="25 0 0 0" ItemsSource="{Binding Leagues}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Expander IsExpanded="{Binding IsExpanded, Mode=TwoWay}" Margin="5" >
                                                    <Expander.Header>
                                                        <TextBlock FontSize="18" Padding="5" Text="{Binding Name}"/>
                                                    </Expander.Header>
                                                    <ItemsControl ItemsSource="{Binding Matches}">
                                                        <ItemsControl.ItemTemplate>
                                                            <DataTemplate>
                                                                <TextBlock FontSize="18" Padding="5" Text="{Binding Source={x:Static sys:String.Empty}}"/>
                                                            </DataTemplate>
                                                        </ItemsControl.ItemTemplate>
                                                    </ItemsControl>
                                                </Expander>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="Match">
                    <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <ItemsControl Margin="25 0 0 0" ItemsSource="{Binding Leagues}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Expander Style="{StaticResource MatchExpanderStyle}" IsExpanded="{Binding IsExpanded, Mode=TwoWay}" Margin="5">                                                
                                                    <Expander.Header>
                                                        <TextBlock Visibility="Hidden" FontSize="18" Padding="5" Text="{Binding Name}"/>
                                                    </Expander.Header>
                                                    <ItemsControl ItemsSource="{Binding Matches}">
                                                        <ItemsControl.ItemTemplate>
                                                            <DataTemplate>
                                                                <TextBlock FontSize="18" Padding="5" Text="{Binding Name}"/>
                                                            </DataTemplate>
                                                        </ItemsControl.ItemTemplate>
                                                    </ItemsControl>
                                                </Expander>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </DataTemplate>
    
                            </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
        <ListView.GroupStyle>
            ...
        </ListView.GroupStyle>
    </ListView>
    

    将整个内容放在Window.ResourcesApplication.Resources 下。我已将Visibility 更改为隐藏在ToggleButton 中,名称为HeaderSite。一切都是VS自动生成的。

    <SolidColorBrush x:Key="Expander.MouseOver.Circle.Stroke" Color="#FF3C7FB1"/>
                <SolidColorBrush x:Key="Expander.MouseOver.Circle.Fill" Color="Transparent"/>
                <SolidColorBrush x:Key="Expander.MouseOver.Arrow.Stroke" Color="#222"/>
                <SolidColorBrush x:Key="Expander.Pressed.Circle.Stroke" Color="#FF526C7B"/>
                <SolidColorBrush x:Key="Expander.Pressed.Circle.Fill" Color="Transparent"/>
                <SolidColorBrush x:Key="Expander.Pressed.Arrow.Stroke" Color="#FF003366"/>
                <SolidColorBrush x:Key="Expander.Disabled.Circle.Stroke" Color="DarkGray"/>
                <SolidColorBrush x:Key="Expander.Disabled.Circle.Fill" Color="Transparent"/>
                <SolidColorBrush x:Key="Expander.Disabled.Arrow.Stroke" Color="#666"/>
                <SolidColorBrush x:Key="Expander.Static.Circle.Fill" Color="Transparent"/>
                <SolidColorBrush x:Key="Expander.Static.Circle.Stroke" Color="DarkGray"/>
                <SolidColorBrush x:Key="Expander.Static.Arrow.Stroke" Color="#666"/>
                <Style x:Key="ExpanderRightHeaderStyle" TargetType="{x:Type ToggleButton}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                <Border Padding="{TemplateBinding Padding}">
                                    <Grid Background="Transparent" SnapsToDevicePixels="False">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="19"/>
                                            <RowDefinition Height="*"/>
                                        </Grid.RowDefinitions>
                                        <Grid>
                                            <Grid.LayoutTransform>
                                                <TransformGroup>
                                                    <TransformGroup.Children>
                                                        <TransformCollection>
                                                            <RotateTransform Angle="-90"/>
                                                        </TransformCollection>
                                                    </TransformGroup.Children>
                                                </TransformGroup>
                                            </Grid.LayoutTransform>
                                            <Ellipse x:Name="circle" Fill="{StaticResource Expander.Static.Circle.Fill}" HorizontalAlignment="Center" Height="19" Stroke="{StaticResource Expander.Static.Circle.Stroke}" VerticalAlignment="Center" Width="19"/>
                                            <Path x:Name="arrow" Data="M 1,1.5 L 4.5,5 L 8,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="false" Stroke="{StaticResource Expander.Static.Arrow.Stroke}" StrokeThickness="2" VerticalAlignment="Center"/>
                                        </Grid>
                                        <ContentPresenter HorizontalAlignment="Center" Margin="0,4,0,0" Grid.Row="1" RecognizesAccessKey="True" SnapsToDevicePixels="True" VerticalAlignment="Top"/>
                                    </Grid>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsChecked" Value="true">
                                        <Setter Property="Data" TargetName="arrow" Value="M 1,4.5  L 4.5,1  L 8,4.5"/>
                                    </Trigger>
                                    <Trigger Property="IsMouseOver" Value="true">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.MouseOver.Circle.Stroke}"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.MouseOver.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.MouseOver.Arrow.Stroke}"/>
                                    </Trigger>
                                    <Trigger Property="IsPressed" Value="true">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.Pressed.Circle.Stroke}"/>
                                        <Setter Property="StrokeThickness" TargetName="circle" Value="1.5"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.Pressed.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.Pressed.Arrow.Stroke}"/>
                                    </Trigger>
                                    <Trigger Property="IsEnabled" Value="false">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.Disabled.Circle.Stroke}"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.Disabled.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.Disabled.Arrow.Stroke}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style x:Key="ExpanderUpHeaderStyle" TargetType="{x:Type ToggleButton}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                <Border Padding="{TemplateBinding Padding}">
                                    <Grid Background="Transparent" SnapsToDevicePixels="False">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="19"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid>
                                            <Grid.LayoutTransform>
                                                <TransformGroup>
                                                    <TransformGroup.Children>
                                                        <TransformCollection>
                                                            <RotateTransform Angle="180"/>
                                                        </TransformCollection>
                                                    </TransformGroup.Children>
                                                </TransformGroup>
                                            </Grid.LayoutTransform>
                                            <Ellipse x:Name="circle" Fill="{StaticResource Expander.Static.Circle.Fill}" HorizontalAlignment="Center" Height="19" Stroke="{StaticResource Expander.Static.Circle.Stroke}" VerticalAlignment="Center" Width="19"/>
                                            <Path x:Name="arrow" Data="M 1,1.5 L 4.5,5 L 8,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="false" Stroke="{StaticResource Expander.Static.Arrow.Stroke}" StrokeThickness="2" VerticalAlignment="Center"/>
                                        </Grid>
                                        <ContentPresenter Grid.Column="1" HorizontalAlignment="Left" Margin="4,0,0,0" RecognizesAccessKey="True" SnapsToDevicePixels="True" VerticalAlignment="Center"/>
                                    </Grid>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsChecked" Value="true">
                                        <Setter Property="Data" TargetName="arrow" Value="M 1,4.5  L 4.5,1  L 8,4.5"/>
                                    </Trigger>
                                    <Trigger Property="IsMouseOver" Value="true">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.MouseOver.Circle.Stroke}"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.MouseOver.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.MouseOver.Arrow.Stroke}"/>
                                    </Trigger>
                                    <Trigger Property="IsPressed" Value="true">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.Pressed.Circle.Stroke}"/>
                                        <Setter Property="StrokeThickness" TargetName="circle" Value="1.5"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.Pressed.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.Pressed.Arrow.Stroke}"/>
                                    </Trigger>
                                    <Trigger Property="IsEnabled" Value="false">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.Disabled.Circle.Stroke}"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.Disabled.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.Disabled.Arrow.Stroke}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style x:Key="ExpanderLeftHeaderStyle" TargetType="{x:Type ToggleButton}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                <Border Padding="{TemplateBinding Padding}">
                                    <Grid Background="Transparent" SnapsToDevicePixels="False">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="19"/>
                                            <RowDefinition Height="*"/>
                                        </Grid.RowDefinitions>
                                        <Grid>
                                            <Grid.LayoutTransform>
                                                <TransformGroup>
                                                    <TransformGroup.Children>
                                                        <TransformCollection>
                                                            <RotateTransform Angle="90"/>
                                                        </TransformCollection>
                                                    </TransformGroup.Children>
                                                </TransformGroup>
                                            </Grid.LayoutTransform>
                                            <Ellipse x:Name="circle" Fill="{StaticResource Expander.Static.Circle.Fill}" HorizontalAlignment="Center" Height="19" Stroke="{StaticResource Expander.Static.Circle.Stroke}" VerticalAlignment="Center" Width="19"/>
                                            <Path x:Name="arrow" Data="M 1,1.5 L 4.5,5 L 8,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="false" Stroke="{StaticResource Expander.Static.Arrow.Stroke}" StrokeThickness="2" VerticalAlignment="Center"/>
                                        </Grid>
                                        <ContentPresenter HorizontalAlignment="Center" Margin="0,4,0,0" Grid.Row="1" RecognizesAccessKey="True" SnapsToDevicePixels="True" VerticalAlignment="Top"/>
                                    </Grid>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsChecked" Value="true">
                                        <Setter Property="Data" TargetName="arrow" Value="M 1,4.5  L 4.5,1  L 8,4.5"/>
                                    </Trigger>
                                    <Trigger Property="IsMouseOver" Value="true">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.MouseOver.Circle.Stroke}"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.MouseOver.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.MouseOver.Arrow.Stroke}"/>
                                    </Trigger>
                                    <Trigger Property="IsPressed" Value="true">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.Pressed.Circle.Stroke}"/>
                                        <Setter Property="StrokeThickness" TargetName="circle" Value="1.5"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.Pressed.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.Pressed.Arrow.Stroke}"/>
                                    </Trigger>
                                    <Trigger Property="IsEnabled" Value="false">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.Disabled.Circle.Stroke}"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.Disabled.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.Disabled.Arrow.Stroke}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style x:Key="ExpanderHeaderFocusVisual">
                    <Setter Property="Control.Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Border>
                                    <Rectangle Margin="0" SnapsToDevicePixels="true" Stroke="Black" StrokeThickness="1" StrokeDashArray="1 2"/>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style x:Key="ExpanderDownHeaderStyle" TargetType="{x:Type ToggleButton}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                <Border Padding="{TemplateBinding Padding}">
                                    <Grid Background="Transparent" SnapsToDevicePixels="False">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="19"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <Ellipse x:Name="circle" Fill="{StaticResource Expander.Static.Circle.Fill}" HorizontalAlignment="Center" Height="19" Stroke="{StaticResource Expander.Static.Circle.Stroke}" VerticalAlignment="Center" Width="19"/>
                                        <Path x:Name="arrow" Data="M 1,1.5 L 4.5,5 L 8,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="false" Stroke="{StaticResource Expander.Static.Arrow.Stroke}" StrokeThickness="2" VerticalAlignment="Center"/>
                                        <ContentPresenter Grid.Column="1" HorizontalAlignment="Left" Margin="4,0,0,0" RecognizesAccessKey="True" SnapsToDevicePixels="True" VerticalAlignment="Center"/>
                                    </Grid>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsChecked" Value="true">
                                        <Setter Property="Data" TargetName="arrow" Value="M 1,4.5  L 4.5,1  L 8,4.5"/>
                                    </Trigger>
                                    <Trigger Property="IsMouseOver" Value="true">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.MouseOver.Circle.Stroke}"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.MouseOver.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.MouseOver.Arrow.Stroke}"/>
                                    </Trigger>
                                    <Trigger Property="IsPressed" Value="true">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.Pressed.Circle.Stroke}"/>
                                        <Setter Property="StrokeThickness" TargetName="circle" Value="1.5"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.Pressed.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.Pressed.Arrow.Stroke}"/>
                                    </Trigger>
                                    <Trigger Property="IsEnabled" Value="false">
                                        <Setter Property="Stroke" TargetName="circle" Value="{StaticResource Expander.Disabled.Circle.Stroke}"/>
                                        <Setter Property="Fill" TargetName="circle" Value="{StaticResource Expander.Disabled.Circle.Fill}"/>
                                        <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource Expander.Disabled.Arrow.Stroke}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style x:Key="MatchExpanderStyle" TargetType="{x:Type Expander}">
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                    <Setter Property="Background" Value="Transparent"/>
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                    <Setter Property="BorderBrush" Value="Transparent"/>
                    <Setter Property="BorderThickness" Value="1"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Expander}">
                                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="3" SnapsToDevicePixels="true">
                                    <DockPanel>
                                        <ToggleButton x:Name="HeaderSite" Visibility="Hidden" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}" Content="{TemplateBinding Header}" DockPanel.Dock="Top" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FocusVisualStyle="{StaticResource ExpanderHeaderFocusVisual}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" MinWidth="0" MinHeight="0" Padding="{TemplateBinding Padding}"  VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                        <ContentPresenter x:Name="ExpandSite" DockPanel.Dock="Bottom" Focusable="false" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Visibility="Collapsed" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                    </DockPanel>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsExpanded" Value="true">
                                        <Setter Property="Visibility" TargetName="ExpandSite" Value="Visible"/>
                                    </Trigger>
                                    <Trigger Property="ExpandDirection" Value="Right">
                                        <Setter Property="DockPanel.Dock" TargetName="ExpandSite" Value="Right"/>
                                        <Setter Property="DockPanel.Dock" TargetName="HeaderSite" Value="Left"/>
                                        <Setter Property="Style" TargetName="HeaderSite" Value="{StaticResource ExpanderRightHeaderStyle}"/>
                                    </Trigger>
                                    <Trigger Property="ExpandDirection" Value="Up">
                                        <Setter Property="DockPanel.Dock" TargetName="ExpandSite" Value="Top"/>
                                        <Setter Property="DockPanel.Dock" TargetName="HeaderSite" Value="Bottom"/>
                                        <Setter Property="Style" TargetName="HeaderSite" Value="{StaticResource ExpanderUpHeaderStyle}"/>
                                    </Trigger>
                                    <Trigger Property="ExpandDirection" Value="Left">
                                        <Setter Property="DockPanel.Dock" TargetName="ExpandSite" Value="Left"/>
                                        <Setter Property="DockPanel.Dock" TargetName="HeaderSite" Value="Right"/>
                                        <Setter Property="Style" TargetName="HeaderSite" Value="{StaticResource ExpanderLeftHeaderStyle}"/>
                                    </Trigger>
                                    <Trigger Property="IsEnabled" Value="false">
                                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
    

    其他所有内容都与此处的旧答案相同:How to bind a list of item in CollectionViewSource?

    【讨论】:

    • 谢谢你,实际上我无法测试你的代码,我明天试试。再次感谢:)
    • @lok​​usking 请看答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-07
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-05
    相关资源
    最近更新 更多