Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 值转换器不适用于caliburn.micro_C#_Windows Runtime_Caliburn.micro - Fatal编程技术网

C# 值转换器不适用于caliburn.micro

C# 值转换器不适用于caliburn.micro,c#,windows-runtime,caliburn.micro,C#,Windows Runtime,Caliburn.micro,我正在构建windows8.1应用程序,并试图篡改caliburn.micro的ConventionManager。我想启用ValueConverters的名称约定绑定。 更具体地说,我有一个ProductViewModels集合,它有两个属性Value和IsValid。我想通过ValueConverter将Value属性绑定到textblock,将IsValid属性绑定到边框的BorderColorBrush 下面是我在app.xaml.cs中配置的代码 var oldApplyConver

我正在构建windows8.1应用程序,并试图篡改caliburn.micro的ConventionManager。我想启用ValueConverters的名称约定绑定。 更具体地说,我有一个ProductViewModels集合,它有两个属性Value和IsValid。我想通过ValueConverter将Value属性绑定到textblock,将IsValid属性绑定到边框的BorderColorBrush

下面是我在app.xaml.cs中配置的代码

 var oldApplyConverterFunc = ConventionManager.ApplyValueConverter;
        ConventionManager.ApplyValueConverter = (binding, bindableProperty, property) =>
        {
            if (bindableProperty == Control.BorderBrushProperty && typeof(bool).IsAssignableFrom(property.PropertyType))
                //                                ^^^^^^^           ^^^^^^
                //                             Property in XAML     Property in view-model
                binding.Converter = booleanToBrush;
            //                  ^^^^^^^^^^^^^^^^^^^^^^^^^
            //                 My converter used here. Code never reaches this point

            // else I use the default converter
            else if (bindableProperty == TextBlock.TextProperty && typeof(int).IsAssignableFrom(property.PropertyType))
            {
                //Code reaches this point when it should.
                oldApplyConverterFunc(binding, bindableProperty, property);
            }
            else
            {
                oldApplyConverterFunc(binding, bindableProperty, property);
            }


        };
问题是程序从未输入第一个if子句。有人知道为什么吗

我的VM和xaml就是这些

 public class ProductViewModel
{
    public ProductViewModel(int value)
    {
        _value = value;           
    }

    private int _value;
    public int Value
    {
        get { return _value; }
        set
        {
            _value = value;                
        }
    }

    private bool _isValid;
    public bool IsValid
    {
        get 
        {
            _isValid = some validation logic;
            return _isValid; 
        }          
    }        
}
视图是一个用户控件

<Border x:Name="IsValid">
    <TextBlock x:Name="Value"/>
</Border>