Reputation: 1673
I am trying to find a way how to localize or remove "items" text in Xceed DataGrid for WPF (Community version), which is displayed automatically. Anybody knows how to do it?
Upvotes: 2
Views: 361
Reputation: 5666
Your issue is caused by the "items" label that is hardcoded in the Group's DataTemplate
.
So the solution is to overwrite that DataTemplate
. It is not so difficult if you use implicit data templating: just put your DataTemplate
in the resources of the window with the DataGridControl
:
<Window x:Class="Sample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
Title="MainWindow" Height="400" Width="400">
<Window.Resources>
<xcdg:StringFormatMultiConverter x:Key="stringFormatMultiConverter" />
<DataTemplate x:Key="customGroupTemplate">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<ContentPresenter VerticalAlignment="Center" Content="{Binding Title}" ContentTemplate="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataContext.TitleTemplate}" ContentTemplateSelector="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataContext.TitleTemplateSelector}" />
<TextBlock Text=": " VerticalAlignment="Center" />
<ContentPresenter VerticalAlignment="Center" ContentTemplate="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataContext.ValueTemplate}" ContentTemplateSelector="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataContext.ValueTemplateSelector}">
<ContentPresenter.Content>
<MultiBinding Converter="{StaticResource stringFormatMultiConverter}">
<Binding Path="Value" />
<Binding Path="DataContext.ValueStringFormat" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="DataContext.ValueStringFormatCulture" RelativeSource="{RelativeSource TemplatedParent}" />
</MultiBinding>
</ContentPresenter.Content>
</ContentPresenter>
<TextBlock Text=" (" VerticalAlignment="Center" />
<TextBlock VerticalAlignment="Center" Text="{Binding ItemCount}" />
<TextBlock Text=" " VerticalAlignment="Center" />
<TextBlock Name="suffixRun" Text="položky" VerticalAlignment="Center" />
<TextBlock Text=")" VerticalAlignment="Center" />
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Value="1" Binding="{Binding ItemCount}">
<Setter TargetName="suffixRun" Property="TextBlock.Text" Value="položka" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate DataType="{x:Type xcdg:Group}">
<ContentControl Name="groupContentPresenter" Focusable="False"
ContentTemplate="{StaticResource customGroupTemplate}" Content="{Binding}" />
</DataTemplate>
</Window.Resources>
I sniffed the default template with ILSpy, then I created my own one with the word "items" translated.
I hope it can help you.
Upvotes: 3