我看到了以下问题:how-do-you-apply-a-valueconverter-to-a-convention-based-caliburn-micro-binding .
我无法就该主题发表评论,所以我在这里发表我的问题。
如何使用ConventionManager.ApplyValueConverter
在使用基于约定的绑定(bind)时在 Caliburn.Micro 中用于值转换器?
谁能在这里写一个例子?
最佳答案
ApplyValueConverter
被定义为静态 Func<>
代表 ConventionManager
类。
为了在约定绑定(bind)场景中提供自己的转换器,您需要定义自己的 Func<>
在Configure()
你的 Bootstrap 的方法,像这样:
注意:我假设转换来自 string
至 Opacity
.
public class AppBootstrapper : Bootstrapper<ShellViewModel> {
private static IValueConverter StringToOpacityConverter = new StringToOpacityConverter();
public override void Configure() {
var oldApplyConverterFunc = ConventionManager.ApplyValueConverter;
ConventionManager.ApplyValueConverter = (binding, bindableProperty, property) => {
if (bindableProperty == UIElement.Opacity && typeof(string).IsAssignableFrom(property.PropertyType))
// ^^^^^^^ ^^^^^^
// Property in XAML Property in view-model
binding.Converter = StringToOpacityConverter;
// ^^^^^^^^^^^^^^^^^^^^^^^^^
// Our converter used here.
// else we use the default converter
else
oldApplyConverterFunc(binding, bindableProperty, property);
};
}
}
关于c# - 如何将 ValueConverter 应用于基于约定的 Caliburn.Micro 绑定(bind)示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19175245/