Converter
如果没有下面的注释代码,我如何使用绑定?
public partial class MainWindow : Window
{
public MainWindow()
{ABC = new ABCClass();
InitializeComponent();
//Binding binding = new Binding();
//binding.Source = this;
//binding.Path = new PropertyPath("ABC");
//binding.Mode = BindingMode.OneWay;
//txtKey.SetBinding(TextBox.TextProperty, binding);
Binding binding = new Binding();
binding.Source = this;
binding.Path = new PropertyPath("ABC");
binding.Mode = BindingMode.OneWay;
binding.Converter = new ABCTypeConverter();
txtKey.SetBinding(TextBox.TextProperty, binding);
}
类和Converter
:
public ABCClass ABC { get; set; }
}
public class ABCClass
{
public int A = 1;
public int B = 2;
public int C = 3;
public override string ToString()
{
return (A + B + C).ToString();
}
}
该Converter
代码已被删除,因为站点编辑器不允许“大部分代码”。此代码不需要“模式详细信息”。