WPF 4.8与静态属性结合
我创建ViewBox程序Maticaly。 如何将此控制程序绑定到非静态类的静态特性。
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));
}
这样不起作用。
I create viewbox programmaticaly.
How to bind this control programaticaly to static property of non static class.
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));
}
This way doesnt work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将源设置为
config
的实例:Set the source to an instance of a
Config
:至少您在设置
binding.source
时犯了一个错误。在通常的实例属性的情况下,它应该是具有该属性的对象,在您的情况下,是“ config”的实例。对于静态属性,您无需设置binding.source
。At least you made a mistake in setting
Binding.Source
. In the case of usual instance property, it should be the object which has that property, in your case, the instance of "Config". In the case of static property, you don't need to setBinding.Source
.