如何使用綁定而不需要像以下注釋代碼那樣的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
代碼被刪除,因爲網站編輯不允許 「大多代碼」。此代碼不需要「模式詳細信息」。