Pergunta

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.

Foi útil?

Solução

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>

Outras dicas

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

    }
  }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top