我正在动态生成用户界面的某些元素,以防止在我的Windows中重复相同的代码,因为它们在设计上非常相似。我正在生成的一个控件是切换开关,当前在xaml中这样绑定:
IsChecked="{Binding DebugEnabled, Source={StaticResource NotifyFields}}
生成此控件时,如何将其移到后面的C#代码中?
var tsGeneratedSwitch = new ToggleSwitch
{
Header = "View Information",
OffLabel = "No",
OnLabel = "Yes",
IsChecked = False,
};
tsGeneratedSwitch.Checked += SwitchChanged;
tsGeneratedSwitch.Unchecked += SwitchChanged;
非常感谢
var myBinding = new Binding
{
Source = NotifyFields,
Path = new PropertyPath("DebugEnabled"),
Mode = BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
BindingOperations.SetBinding(tsGeneratedSwitch, CheckBox.IsCheckedProperty, myBinding);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句