在XAML中绑定XAML USERCONTROL
-
26-10-2019 - |
题
我有两个Usercontrol: 主要的 纳德 设置。在 主要的 在某些控件中,我想将XAML中的命令参数设置为 设置. 。在C#代码中很简单,例如:
biSettings.CommandParameter = new Settings();
我该如何在XAML中做到这一点?
CommandParameter="???"
这些设置有我正在使用MVVM的模型。我在这里找到了解决方案 在XAML中绑定USERCONTROL, ,但尚不清楚MVVM,因为在VM中是MV!我正在使用Silverlight 4。
解决方案
假设控件是一个按钮,您可以这样这样:
<Button Command={Binding Foo} Content="Click Me">
<Button.CommandParameter>
<mystuff:Settings />
</Button.CommandParameter>
</Button>
其他提示
Type type = biSettings.GetType();
FieldInfo field = type.GetField("CommandParameter");
if (field != null)
{
DependencyProperty dp = (DependencyProperty)field.GetValue(Result);
if (dp != null)
{
((UserControl)Result).SetValue(dp, YourSettingObject);
}
}
不隶属于 StackOverflow