1

几个小时后我放弃了。我有以下 ListView(在网格中),其中定义了 GroupStyle。我想以某种方式将其取出并将其放入模板或样式中(我很困惑),然后将其添加到我的 ListView 的主要样式(ListViewSimpleStyle)中。这样它就可以在其他地方重复使用,而不是每次都复制粘贴。

我该怎么做?

<ListView Name="LvDataBinding" Grid.Row="0"
                      Style="{StaticResource ListViewSimpleStyle}">                                             
                <!-- Define the grouping-->
                <ListView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock FontSize="12" Text="{Binding Name}"
                                           Foreground="{StaticResource GrayForgroundBrush}"></TextBlock>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </ListView.GroupStyle>
            </ListView>

谢谢

4

1 回答 1

1

Groupstyle 是 Groupbox 的样式,所以我们需要编辑 Groupbox 的样式,我已经更改了 GroupBox HeaderTemplate,因为您想更改 GroupStyle 的 HeaderTemplate。

访问: http: //msdn.microsoft.com/en-us/library/ms754027 (v=vs.90).aspx

并在您自己的列表视图模板样式中添加具有其样式的 GroupBox,即 ListViewSimpleStyle

     <Style x:Key="ListViewSimpleStyle" TargetType="ListView">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListView">
                    <Grid Background="AliceBlue" >


                        <GroupBox>
                            <GroupBox.Style>                                    
                                <Style TargetType="GroupBox">
                                    <Setter Property="HeaderTemplate">
                                        <Setter.Value>
                                            <DataTemplate>
                                                <TextBlock FontSize="12" Text="{Binding Name}" Foreground="{StaticResource GrayForgroundBrush}"/>
                                            </DataTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </GroupBox.Style>
                        </GroupBox>


                        <ItemsPresenter></ItemsPresenter>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
于 2014-01-09T11:04:27.177 回答