سؤال

I have two UserControls: Main nad Settings. In Main in some control I want to set CommandParameter in XAML to Settings. In C# code is simple, like:

biSettings.CommandParameter = new Settings();

How can I do that in XAML?

CommandParameter="???"

The Settings has own model I'm using MVVM. I found solutions here Binding UserControl in XAML, but It is not clear MVVM because in VM is MV! I'm using Silverlight 4.

هل كانت مفيدة؟

المحلول

Let's say the control is a Button, you could so something like this:

<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);

    }
  }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top