组合框IsEnabled绑定问题在Silverlight XAML中 [英] ComboBox IsEnabled Binding Question in Silverlight Xaml

查看:185
本文介绍了组合框IsEnabled绑定问题在Silverlight XAML中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框的XAML如下:

I have a ComboBox whose xaml is as follows

<ComboBox Name="ComboBoxDiscussionType" IsEnabled="{Binding ElementName=ComboBoxDiscussionType, Path=Items.Count, Converter={StaticResource ComboBoxItemsCountToBoolConverter}}"/>

和转换器取Items.Count并检查其是否大于0,如果该值大于0,则启用其他禁用

and the converter takes the Items.Count and checks if its greater than 0 if its greater than 0 then enable it else disable it

我们的目标是使组合框如果ComboBox仅当它有它其他的项目禁用它,
(个体经营绑定到其item.count)

The goal is enable the ComboBox if the ComboBox only if it has Items in it else disable it, ( self Binding to its item.count )

下面是我的转换器,

public class ComboBoxItemsCountToBoolConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return (int)value > 0;
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return null;
    }
}

我如何实现的呢?现在上面绑定给我一个错误

how do i achieve it? right now the above Binding gives me an error

推荐答案

有关,我不明白,在Silverlight中的值由转换器所看到是原因键入双击,但它应该是 INT 。事实上,它是一个 INT WPF的。

For reasons that I don't understand, on Silverlight the value as seen by the converter is of type double but it should be int. In fact it is an int on WPF.

不过既然是这样的话,就处理它的 双击解决了这一问题:

But since this is the case, just processing it as a double fixed the problem:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    return (int)(double)value > 0;
}

奇怪的是,一个更传统的相对源绑定不工作之一:

Strangely enough, a more traditional relative source binding doesn't work either:

<Binding RelativeSource="{RelativeSource Self}" .../>

但你的原始元素名称绑定的作用:

but your original element name binding does:

<ComboBox Name="ComboBoxDiscussionType" IsEnabled="{Binding ElementName=ComboBoxDiscussionType, Path=Items.Count, Converter={StaticResource ComboBoxItemsCountToBoolConverter}}"/>

这似乎是pretty车给我,但Silverlight是一个奇怪的野兽的时候。

This seems pretty buggy to me, but Silverlight is a strange beast sometimes.

这篇关于组合框IsEnabled绑定问题在Silverlight XAML中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆