0
MVVM에서 연결된 속성을 사용하여 흥미로운 문제가 발생했습니다. WorkTypeEnum (나는 그것이 MyControl.DoWork의 인스턴스를 실행할 수 있도록 내가 버튼에 WorkType 바인딩 수 있는지 궁금MVVM 연결된 속성 대상 및 원래 컨트롤
public static DependencyProperty WorkTypeProperty = DependencyProperty.RegisterAttached("WorkType",
typeof(WorkTypeEnum),
typeof(MyControl),
new PropertyMetadata(WorkTypeChanged));
public static void SetWorkType(DependencyObject target, WorkTypeEnum value)
{
target.SetValue(WorkTypeProperty, value);
}
public static WorkTypeEnum GetWorkType(DependencyObject target)
{
return (WorkTypeEnum)target.GetValue(WorkTypeProperty);
}
public static void WorkTypeClick(object sender, MouseButtonEventArgs e)
{
var control = (Control)sender;
WorkTypeEnume workType = (WorkTypeEnum)control.GetValue(WorkTypeProperty);
(Instance of MyControl).DoWork(workType); ??? <--How to know the instance of MyControl?
}
private static void WorkTypeChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
{
var control = target as Control;
if (control != null)
{
if ((e.NewValue != null) && (e.OldValue == null))
{
control.MouseDown += WorkTypeClick;
}
else if ((e.NewValue == null) && (e.OldValue != null))
{
control.MouseDown -= WorkTypeClick;
}
}
}
을 :
나는 다음과 같이 버튼에 WorkType라는 연결된 속성을 만드는 중이라서 작업 유형)?
어쨌든 단추에 MyControl 인스턴스를 할당 할 수 있습니까?
정말 고마워요!