Mvvmlight ToolKit. Net4.5 version CanExecute cannot refresh interface bug

Source: Internet
Author: User

A problem recurs

1. In the latest version of the v5.1 mvvmlight (in fact, the problem is very early), found that canexecute can not work very well. A simple project, only MainWindow and Mainwindowviewmodel, the code is as follows

MainWindow.xaml

<Windowx:class= "Mvvmlighterror.mainwindow"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"Title= "MainWindow"Height= " the"Width= "525">    <Grid>        <ButtonWidth= "+"Height= "+"Content= "OK"Command="{Binding Okcommand}"></Button>        <ButtonWidth= "+"Height= "+"Margin= "0,100,0,0"Content= "Changeenable"Command="{Binding Changeenablecommand}"></Button>    </Grid></Window>

MainWindow.xaml.cs

 Public Partial class Mainwindow:window    {        public  MainWindow ()        {            InitializeComponent ();              This New Mainwindowviewmodel ();        }    }

MainWindowViewModel.cs

 Public classMainwindowviewmodel:viewmodelbase {Private BOOL_isenabled;  PublicRelaycommand Okcommand {Get; Set; }         PublicRelaycommand Changeenablecommand {Get; Set; }         PublicMainwindowviewmodel () {Okcommand=NewRelaycommand (Okcommandhanlder, Canokcommandexecute); Changeenablecommand=NewRelaycommand (Changeenablecommandhandler); }        Private voidOkcommandhanlder () {}Private BOOLCanokcommandexecute () {return_isenabled; }        Private voidChangeenablecommandhandler () {_isenabled= !_isenabled; }    }

However, to execute the code, click the Changeenable button and the OK button will not change the available state.

OK, let's not change the code, change the assembly target framework from the original. net4.5 to. net4.0, remove the reference to Mvvmlighttoolkit accordingly, and re-add the corresponding version of Mvvmlighttoolkit

Pm> Install-package Mvvmlight

To execute the code, click the Changeenable button and the OK button can change the available status accordingly.

Two issues

The first is to Mvvmlighttoolkit official website to find relevant information, and then the release of the log to see the following important records

There's a solution, but why?

So I went to Mvvmlight's official website.

Find a description of the two key sections below

As a result of the humility of the foreigner, and the reason for the problem, the author wants to transplant the mvvmlight framework into a PCL, but the PCL has a lot of limitations and there is no commandmanager, so it is not possible to provide a "command whether control control is available" function, but then gives a solution

That's where. Modify the namespace GalaSoft.MvvmLight.Command to GALASOFT.MVVMLIGHT.COMMANDWPF when Net4.5 or later uses the corresponding Mvvmlight version.

Here, the ins and outs and the solution are clear.

Record, hoping to help the same pit students.

http://mvvmlight.codeplex.com/workitem/7659

Demo Download: Mvvmlighterror.rar

Mvvmlight ToolKit. Net4.5 version CanExecute cannot refresh interface bug

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.