简体   繁体   English

为什么我的某些按钮在运行时被禁用?

[英]Why are some of my buttons disabled at runtime?

When the window is opened, Abort is clickable, but all of the other buttons are not. 打开窗口后,可以单击“ Abort ,但其他所有按钮都不是。 I put breakpoints at my getters: 我在获取器上设置了断点:

public ICommand OkCommand
        {
            get { return _okCommand; }
        }

and the button is disabled after it is called. 并且该按钮在调用后被禁用。 I feel like I'm missing something obvious here. 我觉得这里缺少明显的东西。 Is my binding not setup correctly? 我的绑定设置不正确吗? Or is it not being correctly initialized? 还是没有正确初始化?

My ViewModel constructor: 我的ViewModel构造函数:

[ImportingConstructor]
        public MyViewModel(IMyViewModel view)
            : base(view)
        {
            _okCommand = new DelegateCommand(OkHandler, IsValid);
            _refreshCommand = new DelegateCommand(RefreshHandler, IsValid);
            _testConnCommand = new DelegateCommand(TestConnectionHandler, IsValid);
        }

My XAML for two of the buttons. 我的XAML中的两个按钮。

<StackPanel Orientation="Horizontal" Margin="0,14" HorizontalAlignment="Center" DockPanel.Dock="Bottom">
            <Button Command="{Binding OkCommand}" Content="Ok" IsDefault="True" TabIndex="3" Margin="5,0"/>
            <Button Content="Abort" IsCancel="True" TabIndex="4" Margin="0"/>
        </StackPanel>

The second parameter of the DelegateCommand constructor is a Func that tells if the Command is executable. DelegateCommand构造函数的第二个参数是Func ,它指示Command是否可执行。 WPF uses this to determine if buttons, etc should be enabled. WPF使用它来确定是否应启用按钮等。

I would check your IsValid Func / method whether it works okay, that is: returns true . 我将检查您的IsValid Func /方法是否正常,即:返回true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM