xaml TextBlock in listview not aligning right - c#

I want to align the column headers to the left and the detail in the column to the right.
The header I get right, but the detail (textBlock) does not want to align to the right. Please help. Here is my code
<ListView HorizontalAlignment="Stretch"
ItemsSource="{Binding Trans}"
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="5"
ScrollViewer.VerticalScrollBarVisibility="Auto"
MaxHeight="230">
<!--Align column header to the left-->
<ListView.Resources>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
</Style>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
</ListView.Resources>
<ListView.View>
<GridView ScrollViewer.HorizontalScrollBarVisibility="Auto">
<GridViewColumn Header="Amount" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Foreground="Black" HorizontalAlignment="Right" Text="{Binding Path=Amount, StringFormat=N2}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>

Please add the following attribute to text block and check
TextAlignment="Right"
to TextBlock node in Data template
Also if that didn't solve please try adding
Setter Property="HorizontalContentAlignment" Value="Right" to listview item Style

This should work,
<GridView ScrollViewer.HorizontalScrollBarVisibility="Auto">
<GridViewColumn Header="Amount" >
<GridViewColumn.CellTemplate >
<DataTemplate >
<StackPanel Width="200" >
<TextBlock Foreground="Black" TextAlignment="Right" Text="{Binding Path=Amount, StringFormat=N2}"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>

Try to play with something like this :
<ListView Grid.IsSharedSizeScope="True">
<ListView.Resources>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
</Style>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalAlignment" Value="Stretch"/> <!-- Redundent -->
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn Header="Amount" >
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A" />
</Grid.ColumnDefinitions>
<TextBlock Foreground="Black" Background="AliceBlue" Text="{Binding}"/>
</Grid>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A" />
</Grid.ColumnDefinitions>
<TextBlock Foreground="Black" Background="AliceBlue" HorizontalAlignment="Right" Text="{Binding Path=Amount}"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>

Related

How to remove header of gridview column in wpf

I have a ListView with GridView content as below. I just add the delete and edit button to the end of each row. So i don't need the header for those columns. I collopsed the headers for those columns, this removes the headers but the place of the header of the columns looks like white as below. How to set the style for those columns as the header bar style ?
<Style x:Key="sahin" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed"></Setter>
</Style>
<ListView Grid.Row="3" ItemsSource="{Binding deckList}" >
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="Surname" Width="120" DisplayMemberBinding="{Binding SurName}" />
<GridViewColumn HeaderContainerStyle="{StaticResource sahin}" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Style="{StaticResource noBackgroundStyle}">
<Image Source="/KillCard;component/Resources/Images/delete.png" Width="16"></Image>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn HeaderContainerStyle="{StaticResource sahin}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Style="{StaticResource noBackgroundStyle}">
<Image Source="/KillCard;component/Resources/Images/edit.png" Width="16"></Image>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
The code snippet shown below helped me.
<Style x:Key="sahin" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Border x:Name="HeaderBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,1,0,1" Background="{TemplateBinding Background}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

How to set TextBlock to fill the WPF ListView row height?

I set the background of my TextBlocks to different colors over the alternating colors. As you can see there is some gaps that are not colored in red:
Is there a way for me to remove those margins/spacing or stretch my TextBlock to completely fill those areas so the entire column region is colored?
Or is there a way to set the entire ListViewItem BG color?
Here is my XAML code:
<Window x:Class="ProfitTracker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ProfitTracker"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Title="MainWindow" Height="450" Width="1200">
<Window.Resources>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="#1e1e1e"></Setter>
<Setter Property="Foreground" Value="#ffffff"></Setter>
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Margin" Value="0"/>
<Setter Property="BorderThickness" Value="0"/>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#3c3c3c"></Setter>
<Setter Property="Foreground" Value="#ffffff"></Setter>
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Margin" Value="0"/>
<Setter Property="BorderThickness" Value="0"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Viewbox Stretch="Uniform">
<ListView Grid.Row="4" Grid.Column="0" Margin="0,0,0,0" ItemsSource="{Binding Coins}" Name="Tasks" Height="250" AlternationCount="2">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="" Width="25" DisplayMemberBinding="{Binding Path=Value.X}">
</GridViewColumn>
<GridViewColumn Header="" Width="25" DisplayMemberBinding="{Binding Path=Value.X}"></GridViewColumn>
<GridViewColumn Header="Symbol" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.Symbol}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Lowest" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.LowestDailyPriceDisplay}" Foreground="#ff0000" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Price" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.PriceDecimalDisplay}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Highest" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.HighestDailyPriceDisplay}" Foreground="#00ff00" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Unit Price" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.Balance.UnitPriceDisplay}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Amount" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.Balance.AvailableAmountDisplay}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Capital" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.Balance.TotalValueDisplay}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Profit" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.Balance.ProfitDisplay}" Background="{Binding Path=Value.Balance.ProfitPercentageColor}" Foreground="{Binding Path=Value.Balance.ProfitColor}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="PNL %" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.Balance.ProfitPercentageDisplay}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Day %" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.PriceChangeInPercentDailyDisplay}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Hour %" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.PriceChangeInPercentHourlyDisplay}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Min %" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.PriceChangeInPercentMinutelyDisplay}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Vol BTC/h" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.LastHourVolumeInBtcDisplay}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Net BTC/m" Width="70">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.LastMinuteVolumeInBtcDisplay}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</Viewbox>
</Window>
I tried DataTriggers but I am unable to set the ListViewItem background color based on its column header, for example "Profit":
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Name}" Value="Profit">
<Setter Property="Background" Value="Red" />
</DataTrigger>
Is there a way to access the column header from a listviewitem reference?
The problem in your case is, that control template for the ListViewItem has a Border with Padding=2. The only possibility to get rid of it I see to replace the control template with own. So you can add following to your ListView :
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem" BasedOn="{StaticResource {x:Type ListViewItem}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="Border" Padding="0" SnapsToDevicePixels="true" Background="{TemplateBinding Background}">
<GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
For more details see also ListView Styles and Templates
If you need you can also customize the VisualStateManager.

WPF Evenly distribute content Expander.Header in the column DataGrid

I wrote a UserControl with two levels of Expander. Expander.Header distributes the nested Grid / StackPanel / Docpanel unevenly. How can I align the elements on the grid in such a structure?
My view:
My user control xaml:
<UserControl x:Class="UserInterface.UserStructuresControl"
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"
xmlns:local="clr-namespace:UserInterface"
xmlns:res="clr-namespace:MigrationTool.Localization;assembly=MigrationTool.Localization"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<CollectionViewSource
x:Key="TableSource"
Source="{Binding Path=TablesCollection}">
</CollectionViewSource>
<DataTemplate x:Key="ExpandableRow">
<Expander>
<Expander.Header>
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="20,0,0,0"/>
</Style>
</StackPanel.Resources>
<CheckBox></CheckBox>
<TextBlock Text="{Binding Path=TableName}"></TextBlock>
<TextBlock HorizontalAlignment="Right" Text="{Binding Path=TableDescription}"></TextBlock>
</StackPanel>
</Expander.Header>
<StackPanel>
<DataGrid ItemsSource="{Binding Path=FieldCollection}"
CanUserAddRows="False"
CanUserDeleteRows="False"
AutoGenerateColumns="False"
>
<DataGrid.Columns>
<DataGridTemplateColumn
Header="{x:Static res:LocResources.UserFieldsHeader}"
Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Expander>
<Expander.Header>
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="20,0,0,0"/>
</Style>
</StackPanel.Resources>
<CheckBox></CheckBox>
<TextBlock Text="{Binding Path=Name}"/>
<TextBlock Text="{Binding Path=Description}"/>
</StackPanel>
</Expander.Header>
<Grid>
<TextBlock Text="{Binding Path=Description}"></TextBlock>
</Grid>
</Expander>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</Expander>
</DataTemplate>
</UserControl.Resources>
<Grid>
<DataGrid
ItemsSource="{Binding Source={StaticResource ResourceKey=TableSource}}"
CanUserAddRows="False"
CanUserDeleteRows="False"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn
SortMemberPath="TableName"
CanUserSort="True"
Header="{x:Static res:LocResources.TableNameHeader}"
CellTemplate="{StaticResource ExpandableRow}"
Width="*">
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</UserControl>
And I also want to ask: if the cursor enters the open area of ​​the nested Expander while the mouse wheel is scrolling, then the external ScrollBar is no longer active. How can I set the scroll wheel only on an external ScrollBar?
In your template replace the stackpanel with a grid that has columns:
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="20,0,0,0"/>
</Style>
</StackPanel.Resources>
<CheckBox></CheckBox>
<TextBlock Text="{Binding Path=Name}"/>
<TextBlock Text="{Binding Path=Description}"/>
</StackPanel>
with this:
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="20,0,0,0"/>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0"></CheckBox>
<TextBlock Grid.Column="1" Text="{Binding Path=Name}"/>
<TextBlock Grid.Column="2" Text="{Binding Path=Description}"/>
</Grid>

WPF - TextBlocks in ListView are not horizontal aligned

I have made a ListView in a WPF-application with different TextBlocks. Each row can contain several TextBlocks, but when a row contains more than one text block, the first one fits to the row, but the following TextBlocks does not align horizontally (see picture). I have no idea what could be the cause of this, so I hope someone could provide some clarification.
Below is the XAML-code.
<ListView ItemsSource="{Binding DataContext.Mechanics, RelativeSource={RelativeSource AncestorType={x:Type Window}}, UpdateSourceTrigger=PropertyChanged}" Height="auto" Width="1330"
Grid.Row="2" Grid.ColumnSpan="13" BorderThickness="0" Background="#FFF2F2F2">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="18"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="22"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="1200"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding MecID}" Grid.Column="0" Padding="0" FontSize="11" Background="#FFF2F2F2"/>
<Label Content="{Binding Name}" Grid.Column="1" Padding="0" FontSize="11" Margin="2, 0, 0, 0"/>
<ListView ItemsSource="{Binding MecJobs, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" Padding="-1" Height="18" Width="1200" Grid.Column="2" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="White">
<ListView.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="0"/>
</Style>
</ListView.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Canvas>
<ListViewItem Width="{Binding EstimatedTimeWidth}" Canvas.Left="{Binding Margin}" Background="{Binding Color}" Height="18"
Padding="0" Margin="0" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<TextBlock TextAlignment="Center" Height="18" Padding="0" Margin="0">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} - {1}">
<Binding Path="RegNumber" />
<Binding Path="CustomerName" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ListViewItem>
</Canvas>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListView>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="0"/>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
EDIT: The problem was solved when the ListView was set with to include a Stackpanel with Orientation="Horizontal".
I think if you add a style for a listview item to the item container style your problem gets fixed.
If not just move the setter to your list box item style.
<ListView ItemsSource="{Binding DataContext.Mechanics, RelativeSource={RelativeSource AncestorType={x:Type Window}}, UpdateSourceTrigger=PropertyChanged}" Height="auto" Width="1330"
Grid.Row="2" Grid.ColumnSpan="13" BorderThickness="0" Background="#FFF2F2F2">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="18"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="22"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="1200"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding MecID}" Grid.Column="0" Padding="0" FontSize="11" Background="#FFF2F2F2"/>
<Label Content="{Binding Name}" Grid.Column="1" Padding="0" FontSize="11" Margin="2, 0, 0, 0"/>
<ListView ItemsSource="{Binding MecJobs, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" Padding="-1" Height="18" Width="1200" Grid.Column="2" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="White">
<ListView.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="0"/>
</Style>
</ListView.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Canvas>
<ListViewItem Width="{Binding EstimatedTimeWidth}" Canvas.Left="{Binding Margin}" Background="{Binding Color}" Height="18"
Padding="0" Margin="0" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<TextBlock TextAlignment="Center" Height="18" Padding="0" Margin="0">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} - {1}">
<Binding Path="RegNumber" />
<Binding Path="CustomerName" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ListViewItem>
</Canvas>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListView>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="0"/>
</Style>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>

Indent first column in GridView of ListView

I have created a gridview by using list view.
There is 2 level of nodes and I would like to indent the child node.
Therefore, I have set the margin in the <ItemPresenter>.
The result looks pretty good but the second and the third column also been indent and not align according to its header column.
Any idea to indent only the first column but not the rest column?
xaml
<ListView Name="listViewResult" Margin="10,231,0,-299" BorderBrush="#FF000000" BorderThickness="1" >
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="280" DisplayMemberBinding="{Binding GrandChildNodeData}" />
<GridViewColumn Header="Date/ Time" Width="160" DisplayMemberBinding="{Binding Time}" />
<GridViewColumn Header="State" Width="160" DisplayMemberBinding="{Binding State}" />
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" Foreground="Silver" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text=" item(s)" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter Margin="20,0,0,0" />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
result
This question has been answered by Magnus in this forum
"You are setting the Margin of the entire GroupItem. You should define a CellTemplate for the first column and set the Margins in there:"
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Margin="20 0 0 0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Date/ Time" Width="160" DisplayMemberBinding="{Binding Time}" />
<GridViewColumn Header="State" Width="160" DisplayMemberBinding="{Binding State}" />
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" Foreground="Silver" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text=" item(s)" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>

Categories

Resources