Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 根据itemsource模型的属性对ItemsControl进行分组_Wpf_Vb.net_Datatemplate_Itemscontrol - Fatal编程技术网

Wpf 根据itemsource模型的属性对ItemsControl进行分组

Wpf 根据itemsource模型的属性对ItemsControl进行分组,wpf,vb.net,datatemplate,itemscontrol,Wpf,Vb.net,Datatemplate,Itemscontrol,在本课程中: Public Class PageBetModel Private _name As String Public Property Name As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property Private _group As String Public Property

在本课程中:

Public Class PageBetModel
Private _name As String

Public Property Name As String
    Get
        Return _name
    End Get
    Set(ByVal value As String)
        _name = value
    End Set
End Property

Private _group As String

Public Property Group As String
    Get
        Return _group
    End Get
    Set(ByVal value As String)
        _group = value
    End Set
End Property
End Class
我想创建一个带有
ItemsControl
的样式,绘制
Name
属性, 并按
属性分组

<ItemsControl ItemsSource="{Binding Path=Model}" ItemsPanel="{DynamicResource MyPanel}" ItemTemplate="{DynamicResource MyTemplate}"/>

<DataTemplate x:Key="MyTemplate">
    <Border MinHeight="100" BorderThickness="0,0,0,2" BorderBrush="#dfe1e0">

            <TextBlock x:Name="RadioButtonText" Margin="16,40,16,16" Width="287" Text="{Binding Path=Name}" FontFamily="Arial" FontSize="17" Foreground="#474747" FontWeight="SemiBold" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalAlignment="Left"/>

    </Border>
</DataTemplate>


我想显示这个简单的设计,但通过
属性使用
扩展器
对不同的名称进行分组。

项资源
设置为分组的
集合视图源

<CollectionViewSource x:Key="cvs" Source="{Binding Path=Model}">
    <CollectionViewSource.GroupDescriptions>
        <PropertyGroupDescription PropertyName="Group" />
    </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<ItemsControl ItemsPanel="{DynamicResource MyPanel}"
            ItemsSource="{Binding Source={StaticResource cvs}}"
            ItemTemplate="{DynamicResource MyTemplate}">
    <ItemsControl.GroupStyle>
        <GroupStyle>
            <GroupStyle.ContainerStyle>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Expander IsExpanded="True">
                                    <Expander.Header>
                                        <TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" />
                                    </Expander.Header>
                                    <ItemsPresenter />
                                </Expander>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </GroupStyle.ContainerStyle>
        </GroupStyle>
    </ItemsControl.GroupStyle>
</ItemsControl>