2 回答
TA贡献1796条经验 获得超4个赞
为了达到你的目的,你需要编写一个类实现IValueConverter接口。
public class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, string language)
{
// Contain your source to target convertion logic.
}
public object ConvertBack(object value, Type targetType,
object parameter, string language)
{
// Contain your target to source convertion logic.
// Only needed if using TwoWay or OneWayToSource Binding Mode.
}
}
然后Binding.Converter在调用SetBinding方法之前将其实例设置为属性 。
Binding MainGridWidthBinding = new Binding("PrValue")
{
Source = this,
Mode = BindingMode.TwoWay,
Converter = new MyConverter(),
};
MainGrid.SetBinding(Grid.WidthProperty, MainGridWidthBinding);
- 2 回答
- 0 关注
- 168 浏览
添加回答
举报