WPF/Silverlight: How do you make a Button call ICommand.CanExecute when the command parameter is changed? -
If the command parameter changes, how do you create a call call ICommand.CanExecute?
This is my current XAML
& lt; Button content = "delete" command = "{binding delete name comma}" commandpalmter = "{binning select itam, elementname = dgrid}" /> Edit It appears that this is only an issue in WPF.
I'm not sure what you're doing wrong, but here's an example of a button A binding effect is controlled by the permiter and the canxicate flag. Your binding parameter is probably not a dependency property, and therefore, when this change occurs, the button is not being notified.
& lt; UserControl x: class = "SilverlightICommandTest.MainPage" xmlns = "http: //schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/ Xaml "xmlns: D =" http://schemas.microsoft.com/compilation/blend / 2008 "xmlns: mc =" http://schemas.openxmlformats.org/markup-compatibility/2006 "xmlns: ct =" clr -namespace: Silverlightmommandstasts "mc: Ignorable =" d "d: DesignHeight =" 300 "D: DesignWidth =" 400 "& gt; & Lt; UserControl.Resources & gt; & Lt; Ct: testmodel x: key = "model" /> & Lt; /UserControl.Resources> & Lt; StackPanel x: name = "layout" orientation = "vertical" background = "white" datacontax = "{static resource model}" & gt; & Lt; Checkbox content = "enable" isChecked = "{Binding TestCmd.CanDoCommand, Mode = TwoWay}" /> & Lt; Grid horizontal alignment = "statch" & gt; & Lt; Grid.ColumnDefinitions & gt; & Lt; Column width = "Auto" /> & Lt; Columns Definition / & gt; & Lt; /Grid.ColumnDefinitions> & Lt; TextBlock Text = "{Binding element name = test slider, path = value}" width = "40" grid. Column = "0" /> & Lt; Slider Name = "TestSlider" min = "0" max = "100" small change = "1" grid. Column = "1" /> & Lt; / Grid & gt; & Lt; Button command = "{binding test CMD}" commandpalmter = "{binding elementman = testSlider, path = value}" content = "do something" /> & Lt; / StackPanel & gt; & Lt; / UserControl & gt; and the code file:
using the system; Using System.Windows; Using System.Windows.Controls; Using System.Windows.Input; Namespace SilverlightICommandTest {Public Partial Class Home Page: UserControl {Public Menus ()} {InitializeComponent (); }} Public Class Testdomel: Dependency Object {Test Commands _ Test CMD = New Test Commands (); Public Test Commend TestCMD {Receive} {_testCmd; }} Public Test Model () {}} Public Selection Test Quantity: Dependency Object, ICMMand {Public Static Only Readability Dependency Property Condo Command Property = Dependency Property Registrar (typing (boolean), typef (test command), new property matadata (false, new property changed callback)); Get Public Boolean Kendo Commands {Return (Boolean) (Canompromp); } Set {set value (canode commodity property, value); }} CanExecuteChanged Public Event Event Handler; Public Test Commands () {} Public Boolean Cancute (Object Parameter) {Return it Conn commandand amp; ((Int32) (double) parameter)% 2 == 0); } Execute public null (object parameter) {message box. Show ("Hey!"); } Private Zero OnCanDoCommandChanged (DependencyPropertyChangedEventArgs args) {If (this.CanExecuteChanged! = Null) {this.CanExecuteChanged (This, New EventArgs ()); }} Private Static Zero CanDoCommandChanged (Dependency Object Sender, DependencyPropertyChangedEventArgs Args) Sender (TestCommand) .OnCanDoCommandChanged (args); In the future, I am doing a bit more research on the first pattern (), and if you still can not understand it then post it after your source code. / P>
Comments
Post a Comment