J
joni7373
Guest
Hello,
I am using a <code>CollectionViewSource</code> as ItemSource for a WPF DataGrid to fill and group the DataGrid: (I fill it with data from a database)
dataTable = new CollectionViewSource
{
Source = Global.dsAuftraege.Tables[0]
};
dataTable.GroupDescriptions.Add(new PropertyGroupDescription("Auftragsnummer"));
For the DataGrid Groups I use the following Style:
<Style x:Key="GroupStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander x:Name="expander" IsExpanded="True"
Background="LightBlue"
Foreground="Black"
>
<Expander.Header>
<DockPanel>
<TextBlock Style="{StaticResource HeaderTextBlock}" x:Name="ExpanderHeader1" Text="{Binding Name}" Margin="5,0,0,0" Width="200"/>
<TextBlock x:Name="ExpanderHeader2" Text="{Binding ItemCount}"/>
<TextBlock x:Name="ExpanderHeader3" Text=""/>
</DockPanel>
</Expander.Header>
<ItemsPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
As you can see I use an <b>Expander</b> and the <b>Expander.Header</b> consists of 3 TextBlocks. <b>And here comes my problem:</b>
In the underlying database I have a column called "State" containing integers from -1 to 2. My DataGrid shows this column too.
Now I want to make the <b>Expander.Header</b> texts <b>bold</b> when there are rows within the Expanders <b>Group</b> with <code>"State"==2</code>.
What is more: I want to <b>count</b> all the rows within a <b>Group</b> with <code>"State"==2</code> and show the count in <b>"ExpanderHeader3"</b> TextBlock.
I tried different approaches in XAML but also in Code behind.
XAML:
I tried different Triggers, but couldn't get it running.
Code behind:
I tried to access the Expander in code behind with VisualTreeHelper, but it did not work.
I think it should be possible to solve this in XAML, but since I am new to it I have no idea how to do it.
I am happy about any suggestion.
Thank you.
Continue reading...
I am using a <code>CollectionViewSource</code> as ItemSource for a WPF DataGrid to fill and group the DataGrid: (I fill it with data from a database)
dataTable = new CollectionViewSource
{
Source = Global.dsAuftraege.Tables[0]
};
dataTable.GroupDescriptions.Add(new PropertyGroupDescription("Auftragsnummer"));
For the DataGrid Groups I use the following Style:
<Style x:Key="GroupStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander x:Name="expander" IsExpanded="True"
Background="LightBlue"
Foreground="Black"
>
<Expander.Header>
<DockPanel>
<TextBlock Style="{StaticResource HeaderTextBlock}" x:Name="ExpanderHeader1" Text="{Binding Name}" Margin="5,0,0,0" Width="200"/>
<TextBlock x:Name="ExpanderHeader2" Text="{Binding ItemCount}"/>
<TextBlock x:Name="ExpanderHeader3" Text=""/>
</DockPanel>
</Expander.Header>
<ItemsPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
As you can see I use an <b>Expander</b> and the <b>Expander.Header</b> consists of 3 TextBlocks. <b>And here comes my problem:</b>
In the underlying database I have a column called "State" containing integers from -1 to 2. My DataGrid shows this column too.
Now I want to make the <b>Expander.Header</b> texts <b>bold</b> when there are rows within the Expanders <b>Group</b> with <code>"State"==2</code>.
What is more: I want to <b>count</b> all the rows within a <b>Group</b> with <code>"State"==2</code> and show the count in <b>"ExpanderHeader3"</b> TextBlock.
I tried different approaches in XAML but also in Code behind.
XAML:
I tried different Triggers, but couldn't get it running.
Code behind:
I tried to access the Expander in code behind with VisualTreeHelper, but it did not work.
I think it should be possible to solve this in XAML, but since I am new to it I have no idea how to do it.
I am happy about any suggestion.
Thank you.
Continue reading...