本地化 Xceed DataGrid

Localizing Xceed DataGrid

我正在尝试找到一种方法来本地化或删除自动显示的 Xceed DataGrid for WPF(社区版)中的 "items" 文本。有人知道怎么做吗?

您的问题是由 GroupDataTemplate 中硬编码的 "items" 标签引起的。

所以解决方案是覆盖 DataTemplate。如果你使用 implicit data templating 并不难:只需将你的 DataTemplateDataGridControl:

放在 window 的资源中
<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" 翻译的词创建了自己的模板。

希望对您有所帮助