我正在尝试找到一种方法,如何在 Xceed DataGrid for WPF(社区版)中本地化或删除“项目”文本,该文本会自动显示。有人知道该怎么做吗?
问问题
305 次
1 回答
3
您的问题是由Group中硬编码的“项目”标签引起的DataTemplate
。
所以解决方案是覆盖它DataTemplate
。如果您使用隐式数据模板,这并不难:只需将您DataTemplate
的资源放入窗口的资源中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>
我用ILSpy嗅探了默认模板,然后我创建了自己的模板,并翻译了单词“items”。
我希望它可以帮助你。
于 2016-06-07T14:44:02.887 回答