ऐसा लगता है कि जब भी कोई प्रासंगिक संपत्ति बदल जाती है तो आपको आदेश पर RaiseCanExecuteChanged को कॉल करना होगा। मुझे लगता है कि यह पहले wpf कमांड मैनेजर द्वारा किया गया था, लेकिन हाल ही में पीसीएल परिवर्तनों ने संभवतः असमर्थनीय बनाया है।
मैं एमवीवीएमक्रॉस का उपयोग करता हूं जिसके लिए एक समान विधि की आवश्यकता होती है, इसलिए मेरे मूल दृश्य मॉडल में मेरे पास एक आदेश पंजीकृत करने की एक विधि है ताकि जब भी कोई संपत्ति बदली जाए तो मैं सभी पंजीकृत कमांड लूप कर सकता हूं और बल को निष्पादित कर सकता हूं फिर से बुलाया चीजों को आसान बनाने के लिए आप इसे इस तरह से कर सकते हैं।
Check out this sample
इस के रूप में, पर शक होने लगता है यहाँ कुछ कोड मैं
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
namespace TestingApp.ViewModel
{
/// <summary>
/// This class contains properties that the main View can data bind to.
/// <para>
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
/// </para>
/// <para>
/// You can also use Blend to data bind with the tool's support.
/// </para>
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class MainViewModel : ViewModelBase
{
private Int32 _increment = 0;
public Int32 Increment
{
get { return _increment; }
set
{
_increment = value;
RaisePropertyChanged("Increment");
GoCommand.RaiseCanExecuteChanged();
}
}
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel()
{
////if (IsInDesignMode)
////{
//// // Code runs in Blend --> create design time data.
////}
////else
////{
//// // Code runs "for real"
////}
}
private RelayCommand _incrementCommand;
public RelayCommand IncrementCommand
{
get
{
if (_incrementCommand == null)
{
_incrementCommand = new RelayCommand(IncrementCommand_Execute);
}
return _incrementCommand;
}
}
private void IncrementCommand_Execute()
{
Increment++;
}
private RelayCommand _goCommand;
public RelayCommand GoCommand
{
get
{
if (_goCommand == null)
{
_goCommand = new RelayCommand(GoCommand_Execute, GoCommand_CanExecute);
}
return _goCommand;
}
}
private bool GoCommand_CanExecute()
{
return Increment > 5;
}
private void GoCommand_Execute()
{
//
}
}
}
का परीक्षण किया है लाइन
GoCommand.RaiseCanExecuteChanged();
canexecute विधि प्रारंभिक कॉल के बाद कभी नहीं कहा जाता है के बिना है , लेकिन लाइन के साथ इसे हर बार कहा जाता है जब वृद्धि संपत्ति बदलती है
वही समस्या, आपको पहले अपनी पोस्ट मिलनी चाहिए थी। मुझे पिछले संस्करण में डाउनग्रेड करना पड़ा। –