我以編程方式創建視圖框。如何以編程方式將此控制元件系結到非靜態類的靜態屬性。
var bindingHeight = new Binding("viewbox_height");
bindingHeight.Source = Config.viewbox_height;
bindingHeight.Mode = BindingMode.TwoWay;
bindingHeight.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
MyViewbox.SetBinding(Viewbox.HeightProperty, bindingHeight);
public class Config
{
public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
public static void OnPropertyChanged([CallerMemberName] string propertyname = null)
{
StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyname));
}
這種方式行不通。
uj5u.com熱心網友回復:
將源設定為 a 的實體Config:
var bindingHeight = new Binding("viewbox_height");
bindingHeight.Source = new Config();
bindingHeight.Mode = BindingMode.TwoWay;
bindingHeight.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
MyViewbox.SetBinding(Viewbox.HeightProperty, bindingHeight);
uj5u.com熱心網友回復:
至少你在設定上犯了一個錯誤Binding.Source。在通常的實體屬性的情況下,它應該是具有該屬性的物件,在您的情況下,是“配置”的實體。在靜態屬性的情況下,您不需要設定Binding.Source.
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/496866.html
上一篇:EmptySortDescriptionCollection和SortDescriptions
下一篇:點擊wpf串列中的專案后彈出內容
