我想要两种状态**(SmallPay,Credit)**,但这是由以前的决定的 UserControl(ItemDetail.xaml)
项目详细信息.xaml
<Border Background="#fb5106" CornerRadius="8" Cursor="Hand">
<Border.InputBindings>
<MouseBinding MouseAction="LeftClick" Command="{Binding Path=ClickPhoneNumberCommand}" CommandParameter="A"/>
</Border.InputBindings>
<TextBlock Text="SmallPay" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" FontSize="32" />
</Border>
<Border Grid.Column="2" Background="#e7001f" CornerRadius="8" Cursor="Hand">
<Border.InputBindings>
<MouseBinding MouseAction="LeftClick" Command="{Binding Path=ClickPhoneNumberCommand}" CommandParameter="B"/>
</Border.InputBindings>
<TextBlock Text="Credit" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" FontSize="32" />
</Border>
视图模型.cs
public DelegateCommand ClickItemCommand
{
get
{
return new DelegateCommand(delegate ()
{
SelectedPopupType = PopupTypes.ItemDetail;
IsShowPopup = true;
});
}
}
public DelegateCommand ClickPhoneNumberCommand
{
get
{
return new DelegateCommand(delegate ()
{
SelectedPopupType = PopupTypes.PhoneNumber;
IsShowPopup = true;
});
}
}
然后,我想获得commandParameter
在UserControl
通过“打开ClickPhoneNumberCommand
”。但是,我不知道如何?有没有没有的方法ViewModel
?
您的代码为每次返回属性返回一个新委托ClickItemCommand
。由于对象引用的工作方式,我认为这不适用于 WPF,我认为您应该使用一个字段来存储对 immutable 的单个引用Command
,如下所示:
private readonly DelegateCommand clickItemCommand;
public MyViewModel()
{
this.clickItemCommand = new DelegateCommand( this.OnItemClick );
}
private void OnItemClick(Object parameter)
{
this.SelectedPopupType = PopupTypes.ItemDetail;
this.IsShowPopup = true;
}
public DelegateCommand ClickItemCommand
{
get { retrn this.clickItemCommand; }
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句