参数可以传递给WPF用户控件吗?
可以将值或参数传递给WPF用户控件吗? 我正在使用MVVM模式。
哪里
ForeColor是托管SampleUserControl View的窗口的Viewmodel中的Type Color或Brush的属性。
顺便说一下,属性应该是Color还是Brush?
是的,你可以使用dependency properties
传递。 您可以在您要传递的类型的usercontrol中创建依赖项属性。 下面是一个小例子,它将向您展示它是如何工作的。
public static readonly DependencyProperty MyCustomProperty = DependencyProperty.Register("MyCustom", typeof(string), typeof(SampleUserControl)); public string MyCustom { get { return this.GetValue(MyCustomProperty) as string; } set { this.SetValue(MyCustomProperty, value); } }
您可以从父虚拟机设置MyCustom
,例如
上述就是C#学习教程:参数可以传递给WPF用户控件吗?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1007456.html