I have a UserControl that receives a parameter form the xaml like this:
<components:MyComponent Sex="MALE"/>
In the MyComponent control I have a ViewModel binded like this:
<UserControl.DataContext>
<components:MyComponentViewModel/>
</UserControl.DataContext>
Also in MyComponent code behind looks like this:
public partial class MyComponent: UserControl
{
public string Sex
{
get => (string)GetValue(SexParamProperty);
set { SetValue(SexParamProperty, value); }
}
public static readonly DependencyProperty SexParamProperty = DependencyProperty.Register(nameof(Sex), typeof(string), typeof(MyComponent));
public MyComponent()
{
InitializeComponent();
}
}
MyComponentViewModel looks like this:
public class MyComponentViewModel: ViewModelBase
{
public string Sex { get; set; }
}
I want the ViewModel to know what the value of Sex from the UserControl is. Is this agains the MVVM pattern or there is a way to do this respecting MVVM? How can I do this?