我创建了一个按钮的覆盖:
公共类 LauncherButton : 按钮
{
公共图像源图像源
{
获取 { 返回 (ImageSource)GetValue(ImageSourceProperty); }
设置 { SetValue(ImageSourceProperty, value); }
}
公共静态只读 DependencyProperty ImageSourceProperty =
DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(LauncherButton), new UIPropertyMetadata(null));
公共字符串标题
{
获取{返回(字符串)GetValue(CaptionProperty);}
设置 { SetValue(CaptionProperty, value); }
}
公共静态只读 DependencyProperty CaptionProperty =
DependencyProperty.Register("Caption", typeof(string), typeof(LauncherButton), new UIPropertyMetadata(null));
公共 ICommand ExecuteCommand
{
获取 { 返回 (ICommand)GetValue(ExecuteCommandProperty); }
设置 { SetValue(ExecuteCommandProperty, value); }
}
公共静态只读 DependencyProperty ExecuteCommandProperty
= DependencyProperty.Register("ExecuteCommand", typeof(ICommand), typeof(LauncherButton));
}
我在这里使用它:
<controls:LauncherButton Caption="Job Phases"
ImageSource="/FMG.UI.WPF.Shared;component/Media/Images/jobphase_128.png"
Margin="10"
Style="{StaticResource TabletLauncherButtonStyle}"
ExecuteCommand="{Binding ItemSelectedCommand}"
CommandParameter="{x:Static enums:View.JobPhases}"/>
和视图的虚拟机:
公共类 TabletHomeViewModel : _HomeViewBase
{
私有 ICommand _ItemSelectedCommand;
公共 ICommand ItemSelectedCommand
{
得到
{
如果(_ItemSelectedCommand == null)
_ItemSelectedCommand = new RelayCommand(p => itemSelecteExecuted((View)p), p => itemSelecteCanExecute((View)p));
返回_ItemSelectedCommand;
}
}
private bool itemSelecteCanExecute(查看视图)
{
返回真;
}
private void itemSelecteExecuted(查看视图)
{
}
}
ItemSelectedCommand 的 Getter 在启动时触发,但是当我单击按钮时,该命令不会触发。输出窗口不显示任何绑定问题。
如果我为它连接一个点击事件,它会触发。
任何人都看到有什么问题吗?
谢谢