Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
<Controls:CustomControl x:Name="myControl" />
like image 748
Matt Overall Avatar asked Apr 11 '11 18:04

Matt Overall


1 Answers

Siblings ViewModel would be in its DataContext try

<TextBox Text="{Binding ElementName=myControl, Path=DataContext.Test}"></TextBox>
<Controls:CustomControl x:Name="myControl" />
like image 139
Muhammad Hasan Khan Avatar answered Nov 15 '22 16:11

Muhammad Hasan Khan