标签: groupstyle

WPF DataGrid的GroupStyle上的HeaderTemplate和ContainerStyle有什么区别?

似乎ContainerStyle优先使用它们HeaderTemplate时指定两者,如下所示;

<controls:DataGrid.GroupStyle>
  <GroupStyle>
    <GroupStyle.HeaderTemplate>
      <DataTemplate>
        <StackPanel>
          <TextBlock Text="{Binding Path=Name}" Background="Yellow" />
        </StackPanel>
      </DataTemplate>
    </GroupStyle.HeaderTemplate>
    <GroupStyle.ContainerStyle>
      <Style TargetType="{x:Type GroupItem}">
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type GroupItem}">
              <Expander IsExpanded="true" Background="Violet">
                <Expander.Header>
                  <DockPanel TextBlock.FontWeight="Bold">
                    <TextBlock Text="{Binding Path=Name}" />
                    <TextBlock Text="{Binding Path=ItemCount}"/>
                  </DockPanel>
                </Expander.Header>
                <ItemsPresenter />
              </Expander>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
    </GroupStyle.ContainerStyle>
  </GroupStyle>
</controls:DataGrid.GroupStyle>
Run Code Online (Sandbox Code Playgroud)

唯一的区别是HeaderTemplate无法访问ItemsPresenter,或与分层数据结构有什么区别?

谢谢!

编辑链接到http://wpftutorial.net/DataGrid.html#grouping.我实际上并没有直接从那里拿到这个例子,但它是一个很棒的网站,所以无论如何他们都可以拥有一个链接.

wpf xaml datagrid .net-3.5 groupstyle

6
推荐指数
1
解决办法
5319
查看次数

在Windows Phone上设置ListView的GroupStyle.Panel

我正在尝试创建一个ListViewwith grouping,其中每个组中的元素都是水平显示的(作为可滚动内容).无论我尝试了什么GroupStyle.Panel,ListView它似乎没有对列表有任何影响.

以下是我的XAML的外观:

  <ListView x:Name="itemListView"
            Padding="10"                
            SelectionMode="None"
            IsSwipeEnabled="False"
            IsItemClickEnabled="True"
            ItemTemplate="{StaticResource listItemTemplate}">
     <ListView.GroupStyle>
        <GroupStyle>
           <GroupStyle.Panel>
              <ItemsPanelTemplate>
                 <ItemsWrapGrid ItemWidth="144" Orientation="Horizontal" />
              </ItemsPanelTemplate>
           </GroupStyle.Panel>
           <GroupStyle.HeaderTemplate>
              <DataTemplate>
                 <Grid>
                    <TextBlock Text="{Binding DisplayTitle}" 
                               Margin="0,10,0,5"
                               Foreground="Black"
                               Style="{StaticResource SubheaderTextBlockStyle}" 
                               TextWrapping="NoWrap" />
                 </Grid>
              </DataTemplate>
           </GroupStyle.HeaderTemplate>
        </GroupStyle>
     </ListView.GroupStyle>
  </ListView>
Run Code Online (Sandbox Code Playgroud)

哪里

<Page.Resources>
   <DataTemplate x:Key="listItemTemplate">
      <Grid Width="144" Margin="5">
         <!-- details -->
      </Grid>
   </DataTemplate>
</Page.Resources>
Run Code Online (Sandbox Code Playgroud)

下图显示了我得到的实际结果,右边显示了我想要的结果.

在此输入图像描述

我尝试使用ItemsWrapGrid具有不同属性的a,我尝试过a StackPanel甚至是a VariableSizedWrapGrid,但是列表项的显示方式没有任何改变.

如何才能做到这一点?

xaml listview groupstyle itemspaneltemplate windows-phone-8.1

6
推荐指数
1
解决办法
1927
查看次数

WPF:由于样式和/或修改的列表框,Groupstyle 无法正常工作

我正在尝试使用 GroupStyle,但不是将组名显示为列表中项目的标题,而是仅显示标题而不显示项目。

它工作得很好,直到我对列表应用了特殊的样式。然后我认为这种风格非常虚假,所以我为这种效果创建了一个用户控件。问题仍然存在。

UserControl 的目的是对所选项目产生扩展效果,通常它可以显示一些信息,然后在扩展时显示更多信息。

用户控制:

<UserControl x:Class="MyProject.CustomUC.ExpandingList"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">

    <Grid>
        <ListBox x:Name="List"
                 ItemsSource="{Binding Path=Collection}">
            <ListBox.Template>
                <ControlTemplate TargetType="ListBox">
                    <Border BorderBrush="Blue" 
                                    BorderThickness="1" 
                                    CornerRadius="2" 
                                    Background="White">
                        <ScrollViewer Focusable="False">
                            <StackPanel Margin="2" IsItemsHost="True" />
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </ListBox.Template>
            <ListBox.GroupStyle>
                <GroupStyle HidesIfEmpty="True">
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Name}"/>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListBox.GroupStyle>
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <Border Margin="4" Name="Border" BorderBrush="Blue" BorderThickness="1" CornerRadius="5" Background="LightBlue">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <ContentPresenter Name="Head"
                                                          Margin="4"
                                                      Visibility="Visible"
                                                      ContentTemplate="{Binding ElementName=List, Path=DataContext.HeadTemplate}"/>
                                        <Border …
Run Code Online (Sandbox Code Playgroud)

wpf listbox groupstyle

5
推荐指数
1
解决办法
2262
查看次数

WPF ListBox的组面板

我有一个列表框,使用GroupStyle对项目进行分组.我想在stackpanel的底部添加一个控件来保存所有组.此附加控件需要是滚动内容的一部分,以便用户滚动到列表的底部以查看控件.如果我使用的是没有组的列表框,则通过修改ListBox模板可以轻松完成此任务.但是,对于分组的项目,ListBox模板似乎仅适用于每个组.我可以修改GroupStyle.Panel,但这不允许我向该面板添加项目.

<ListBox>
<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel/>
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.GroupStyle>
    <GroupStyle>
         <GroupStyle.Panel>
             <ItemsPanelTemplate>
                 <VirtualizingStackPanel/>  **<----- I would like to add a control to this stackpanel**
             </ItemsPanelTemplate>
         </GroupStyle.Panel>
        <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
                <Setter Property="Template">
                     <Setter.Value>
                         <ControlTemplate TargetType="{x:Type GroupItem}">
                              <Grid>
                                  <ItemsPresenter />
                              </Grid>
                         </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>
</ListBox.GroupStyle>
Run Code Online (Sandbox Code Playgroud)

这应该让我知道我需要做什么:

GroupStyleNeeds

wpf listbox groupstyle itemspaneltemplate

4
推荐指数
1
解决办法
6604
查看次数

组样式标题永远不会出现

我的GroupStyle标题永远不会出现在组合框中....

分组工作正常......这是一个具有约束力的问题,但我无法弄明白.

<ComboBox Height="23" Margin="33,45,125,0" Name="comboBox1" VerticalAlignment="Top"  ItemsSource="{Binding}" >
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <Border Background="Red">
                <TextBlock Text="{Binding Path=value}" />
            </Border>
        </DataTemplate>
    </ComboBox.ItemTemplate>
    <ComboBox.GroupStyle>
        <GroupStyle>
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock FontSize="12" FontWeight="Bold" Foreground="DarkGray">
                            <Button Content="{Binding Path=Location}"/>
                            <TextBlock  Text="{Binding Path=Location}" />
                            <Button>bbbb</Button>

                        </TextBlock>
                        <ItemsPresenter/>
                    </StackPanel>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>
    </ComboBox.GroupStyle>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

和代码背后

public class Store
{
    public string Location { get; set; }
    public string value { get; set; }
}

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

        var myData = new …
Run Code Online (Sandbox Code Playgroud)

wpf styles groupstyle

2
推荐指数
1
解决办法
3883
查看次数

基于DateTime创建自定义GroupDescription

我正在对一些数据进行分组,并且PropertyGroupDescription在大多数情况下都能正常工作。但是,如果该属性是DateTime,并且我不想将多个日期作为一个组一起分组(例如每个组中30天左右),则需要一个新的GroupDescription。问题是我不知道该类的实际工作方式以及如何设计此类。

我希望能够继承PropertyGroupDescription(而不是基本的抽象类),因为这也将基于属性,但是在这里,我基于一系列值而不是单个值== 1组进行分组。

有任何指导甚至是这样的准备班吗?

wpf grouping datetime groupstyle

2
推荐指数
1
解决办法
3768
查看次数

DataGrid绑定在GroupItem样式声明中不起作用

我无法在用户控件的资源部分中定义的绑定中正常工作。稍后,当我将它绑定到datagrid的列时,相同的绑定似乎可以在xaml中使用。在样式声明中时,它只是不显示数据。

我得到的错误是

System.Windows.Data错误:40:BindingExpression路径错误:在“对象”“ CollectionViewGroupInternal”(HashCode = 5477078)上找不到“ ReceivedDate”属性。BindingExpression:Path = ReceivedDate; DataItem ='CollectionViewGroupInternal'(HashCode = 5477078); 目标元素是'TextBlock'(Name =''); 目标属性为“文本”(类型为“字符串”)

下面的绑定ReceivedDate在运行时无法解析。

<UserControl.Resources>

    <!-- Grouped Items Header: Show the messages in a group. ex: date received -->
    <Style x:Key="GroupedItemsHeaderStyle" TargetType="{x:Type GroupItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}">
                    <Expander x:Name="exp" IsExpanded="True"
                              Background="LightGray"
                              Foreground="Black">
                        <Expander.Header>
                            <TextBlock Text="{Binding Path=ReceivedDate, Converter={StaticResource DateToSortGroupConverter}}" Foreground="Black"/>
                        </Expander.Header>
                        <ItemsPresenter/>
                    </Expander>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)

在此UserControl的隐藏代码中,我按如下所示设置itemsList。

    void MailController_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "CurrentMailBoxContent")
        {
            var currentMailBox = ((App) Application.Current).MailController.CurrentMailBoxContent;
            var …
Run Code Online (Sandbox Code Playgroud)

wpf xaml binding datagrid groupstyle

1
推荐指数
1
解决办法
934
查看次数