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