WPF自定义按钮控制命令未触发

时间:2013-08-27 18:42:23

标签: wpf binding controls

我创建了一个按钮的覆盖:

public class LauncherButton : Button
{
    public ImageSource ImageSource
    {
        get { return (ImageSource)GetValue(ImageSourceProperty); }
        set { SetValue(ImageSourceProperty, value); }
    }
    public static readonly DependencyProperty ImageSourceProperty =
        DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(LauncherButton), new UIPropertyMetadata(null));


    public string Caption
    {
        get { return (string)GetValue(CaptionProperty); }
        set { SetValue(CaptionProperty, value); }
    }
    public static readonly DependencyProperty CaptionProperty =
        DependencyProperty.Register("Caption", typeof(string), typeof(LauncherButton), new UIPropertyMetadata(null));



    public ICommand ExecuteCommand
    {
        get { return (ICommand)GetValue(ExecuteCommandProperty); }
        set { SetValue(ExecuteCommandProperty, value); }
    }

    public static readonly 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}"/>

和视图的VM:

public class TabletHomeViewModel : _HomeViewBase
{
    private ICommand _ItemSelectedCommand;
    public ICommand ItemSelectedCommand
    {
        get
        {
            if (_ItemSelectedCommand == null)
                _ItemSelectedCommand = new RelayCommand(p => itemSelecteExecuted((View)p), p => itemSelecteCanExecute((View)p));


            return _ItemSelectedCommand;
        }
    }


    private bool itemSelecteCanExecute(View view)
    {
        return true;
    }
    private void itemSelecteExecuted(View view)
    {
    }
}

ItemSelectedCommand的Getter在启动时触发,但是当我点击按钮时,命令不会触发。输出窗口不显示任何绑定问题。

如果我为它点了一个点击事件,就会触发。

任何人都明白了什么?

由于

0 个答案:

没有答案