我在用户控件中使用文本块,但是我需要从其他表单向文本块发送值。当我传递一些值时,它会在文本块中显示,但我需要将数字转换为文本。因此,我在文本块中使用了转换器,但它没有起作用。
<TextBlock Height="21" Name="txtStatus" Width="65" Background="Bisque" TextAlignment="Center" Text="{Binding Path=hM1,Converter={StaticResource TextConvert},Mode=OneWay}"/>
转换器类
class TextConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
if (value.ToString() == "1")
{
return value = "Good";
}
if (value.ToString() == "0")
{
return value = "NIL";
}
}
return value = "";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (string)value;
}
}
这是正确的吗?它有什么问题吗?