Question

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.

Was it helpful?

Solution

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>

OTHER TIPS

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

    }
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top