XAMLの結合XAML USERCONTROL
-
26-10-2019 - |
質問
私は2つのusercontrolsを持っています: 主要 nad 設定。の 主要 ある程度のコントロールでは、XamlのCommandParameterをに設定したい 設定. 。 C#では、次のようにコードが簡単です。
biSettings.CommandParameter = new Settings();
XAMLでそれをするにはどうすればよいですか?
CommandParameter="???"
設定には、MVVMを使用している独自のモデルがあります。ここで解決策を見つけました XAMLの結合UserControl, 、しかし、VMはMVであるため、MVVMは明確ではありません! 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