标签内容的 WPF 转换器

WPF converter for labels' content

我正在尝试覆盖标签的输出,假设它包含 "Account" 并且客户希望将帐户呈现为 "Member"(因此可以将其视为本地化转换器吗?)

我的问题; "hardcoded" 内容可能吗?或者我必须创建一个包含所有标签内容的静态文件(当然还有 iNotifiyStatic)? *用于绑定?

xaml:

 <Label Style="{StaticResource LabelLeft}" Content="Account Name:"></Label>

资源文件:包括来自多个来源的所有尝试heres the most meaningful one

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:converters ="clr-namespace:Company.Resources.Converters">   

<converters:LocationLabelsConverter x:Key="LocationLabelsConverter" />

<Style x:Key="LabelLeft"  TargetType="{x:Type Label}" >
    <Setter Property="Margin" Value="10 0 0 0"></Setter>
    <Setter Property="Height" Value="22"></Setter>
    <Setter Property="Padding" Value="0 0 0 0"></Setter>
    <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
    <!-- Att1 -->
    <!--<Setter Property="TextBlock.Text" Value="{Binding RelativeSource={RelativeSource self},
                                   Path=Content,
                                   Converter={StaticResource LocationLabelsConverter}}"></Setter>-->
    <!-- Att2 -->
    <!--<Setter Property="Content">
        <Setter.Value>
            <Binding Path="Content" RelativeSource="{RelativeSource self}">
                <Binding.Converter>
                    <converters:LocationLabelsConverter/>
                </Binding.Converter>
            </Binding>
        </Setter.Value>  
    </Setter>-->
    <!-- Att3 -->
    <!--<Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource self},
                                   Path=Content,
                                   Converter={StaticResource LocationLabelsConverter}}">
            <Setter Property="Content" Value="Test123"/>
        </DataTrigger>
    </Style.Triggers>-->        
</Style>

这是转换器:

[ValueConversion(typeof(string), typeof(string))]
public sealed class LocationLabelsConverter : IValueConverter
{
    public object Convert(object value, Type targetType,
        object parameter, CultureInfo culture)
    {
        if (value != null)
        {
            return "hello sweety";// (string)value; //The goal here in the end is to run it through a method to replace string with correct text.
        }
        else return null;
    }        

    public object ConvertBack(object value, Type targetType,
        object parameter, CultureInfo culture)
    {
        return (string)value;
    }
}

您可以像这样应用转换器:

<Label Content="{Binding Source='Account Name:', Converter={StaticResource LocationLabelsConverter}"/>