将值发送到 ValueConverter

发布于 2024-12-20 22:23:06 字数 1040 浏览 4 评论 0原文

我有这个 ValueConverter:

public class LabelConverter : IValueConverter
{
    public object Convert(object value,
                          Type targetType,
                          object parameter,
                          System.Globalization.CultureInfo culture)
    {            
        return ApplicationSettings.getTranstaltion(value.ToString());
    }
}

它用于根据所选语言转换一些标签。应传入的值是 labelName,然后在数据库中查找该值。然后选择正确的翻译并将其发回。以下是我使用过的两次尝试,但都失败了:

 <telerik:ChartLegend Header="{Binding Converter={StaticResource LabelConverter},
                              ConverterParameter='lblLegend'}"
                              x:Name="ChartLegend1"
                              />

<telerik:ChartLegend Header="{Binding ElementName=ChartLegend1, Path=Tag
                              Converter={StaticResource LabelConverter}"
                              x:Name="ChartLegend1"
                              Tag="lblLegend"
                              />

有帮助吗?

I have this ValueConverter:

public class LabelConverter : IValueConverter
{
    public object Convert(object value,
                          Type targetType,
                          object parameter,
                          System.Globalization.CultureInfo culture)
    {            
        return ApplicationSettings.getTranstaltion(value.ToString());
    }
}

It is used to convert some labels according to the selected language. The value that should be passed in is the labelName which is then looked up in the database. Then the propper translation is chosen and sent back. Here are the two attempts that I have used but which both failed:

 <telerik:ChartLegend Header="{Binding Converter={StaticResource LabelConverter},
                              ConverterParameter='lblLegend'}"
                              x:Name="ChartLegend1"
                              />

<telerik:ChartLegend Header="{Binding ElementName=ChartLegend1, Path=Tag
                              Converter={StaticResource LabelConverter}"
                              x:Name="ChartLegend1"
                              Tag="lblLegend"
                              />

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬花如无物 2024-12-27 22:23:06

我首先想到的是检查尝试使用 Mode=TwoWay 显式添加绑定模式。

[编辑]
此外,您还应该检查 ApplicationSettings.getTranstaltion() 是否抛出由 Silverlight 静默阻止的异常。最后,value 是否可以为 null?在这种情况下 value.ToString() 可能会抛出异常。

Silverlight 通常会在用户没有注意到的情况下静默处理异常(或者由于您的 Visual Studio 异常设置),因此在后两种情况下,转换器可能不会在不向您显示异常的情况下执行某些操作。

First thing that comes to my mind is to check try adding the binding mode explicitly with Mode=TwoWay.

[Edit]
Additionally you should check if check if ApplicationSettings.getTranstaltion() throws an exception that is silently choked by Silverlight. Lastly, could value ever be null? In that case value.ToString() might throw an exception.

Silverlight often handles exceptions silently without the user noticing it (or due to your Visual Studio exception settings), so in both of the latter cases the converter might not do something without ever presenting an exception to you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文