i want to use DependencyProperty for giving some value to somme userControl, but the value is not set int the userControl. I tried to modify the value in UserControl1 by hand and it works like this
here's a small project with this problem.
the MainWindow.xaml
<local:UserControl1 TextToShow="salutBG"/>
the UserControl1.xaml
<Label Content="{Binding TextToShow}"/>
the UserControl1.xaml.cs
public static readonly DependencyProperty ContactIdProperty =
DependencyProperty.Register(
"TextToShow", // Nom de la propriété
typeof(string), // Type de la propriété
typeof(UserControl1)
);
public string TextToShow
{
get { return GetValue(ContactIdProperty)?.ToString() ?? ""; }
set { SetValue(ContactIdProperty, value); }
}
public UserControl1()
{
InitializeComponent();
var ViewModel = new UserControl1Model();
ViewModel.TextToShow =TextToShow;
DataContext = ViewModel;
}
the UserControl1Model.cs
public class UserControl1Model
{
public string TextToShow { get; set; } = "";
}