3
TextBox의 Text 속성을 ViewModel 속성의 자식으로 바인딩하고 싶습니다.클래스의 속성에 컨트롤 속성을 바인딩합니다. ViewModel
foo.cs :
public class foo()
{
public foo()
{
Bar = "Hello World";
}
public string Bar { Get; private Set;}
//Some functions
}
ViewModel.cs :
public class ViewModel : INotifyPropertyChanged
{
public foo Property { Get; Set; }
//some more properties
public ViewModel()
{
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
Window.xaml.cs :
public ViewModel MyViewModel { get; set; }
public Window()
{
MyViewModel = new ViewModel();
this.DataContext = MyViewModel;
MyViewModel.Property = new foo();
}
다음
내 코드입니다
Window.xaml는 :
<!--
Some controls
-->
<TextBox Text="{Binding Path=Property.Bar}"></TextBox>
또한 this 및 this을 시도했지만 그들 중 누구도 나를 위해 일하지 않는다.