Question

J'ai deux UserControls: principal nad Paramètres . principal dans un certain contrôle Je veux mettre CommandParameter en XAML Paramètres . Dans le code C # est simple, comme:

biSettings.CommandParameter = new Settings();

Comment puis-je faire en XAML?

CommandParameter="???"

Les paramètres a propre modèle j'utilise MVVM. J'ai trouvé des solutions ici Reliure UserControl à XAML , mais ce ne sont pas MVVM clair parce que dans VM est MV ! J'utilise Silverlight 4.

Était-ce utile?

La 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>

Autres conseils

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

    }
  }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top