728x90
View 의 Property 를 ViewModel 에 binding 할 때 Code 에서 직접 binding 하는 방법
public static readonly DependencyProperty SliceOffsetDependency = DependencyProperty.Register("SliceOffset", typeof(int), typeof(DicomView), new PropertyMetadata(10, OnSliceChanged));
private static void OnSliceChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
DicomView view = (DicomView)source;
int newData = (int)e.NewValue;
}
public int SliceOffset
{
get { return (int)GetValue(SliceOffsetDependency); }
set { SetValue(SliceOffsetDependency, value); }
}
public DicomView()
{
InitializeComponent();
this.DataContext = new DicomViewModel();
Binding sliceBinding = new Binding("SliceOffset");
sliceBinding.Source = this.DataContext;
sliceBinding.Mode = BindingMode.TwoWay;
BindingOperations.SetBinding(this, DicomView.SliceOffsetDependency, sliceBinding);
}
728x90
728x90