WPF Bind to ViewModel of another element
Just an example. The CustomControl has a ViewModel with a property called "Test"
How could I bind the textbox to that specific property? Can you access the siblings ViewModel?
<TextBox Text="{Binding ElementName=myControl, Path=ViewModel.Test}"></TextBox>
<开发者_JAVA技巧;Controls:CustomControl x:Name="myControl" />
Siblings ViewModel would be in its DataContext try
<TextBox Text="{Binding ElementName=myControl, Path=DataContext.Test}"></TextBox>
<Controls:CustomControl x:Name="myControl" />
May be this is what you required-
<TextBox Text="{Binding Source={x:Static local:VieModel}, Path=Test}"></TextBox>
<Controls:CustomControl x:Name="myControl" />
Don't forgot to add the markup extension to include the namespace where your class Viewmodel exists - xmlns:local="clr-namespace:ViewModel NameSpace"
精彩评论