c# - AppCommand are not supported in a Windows Presentation Foundation (WPF) project -
i trying run code question "understanding icommand implementation without mvvm" in vs2012 (window 7) getting errors: "appcommand not supported in windows presentation foundation (wpf) project"
well, wrong or should in order run code question?
mainwindow.xaml.cs:
using system; using system.collections.generic; using system.linq; using system.text; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes; namespace sewpfunderstandingicommandwithout_mvvm { public partial class mainwindow : window { public mainwindow() { initializecomponent(); appcommands.anycommand.canexecutechanged += myeventhandler; } private void button1_click(object sender, routedeventargs e) { // nothing moment } private void myeventhandler(object sender, eventargs e) { console.writeline("myeventhandler called"); } } public static class appcommands { private static icommand anycommand = new mycommand(); public static icommand anycommand { { return anycommand; } } } public class mycommand : icommand { bool canexecute; public void execute(object parameter) { console.writeline("execute called!"); } public bool canexecute(object parameter) { console.writeline("canexecute called!"); return canexecuteresult; } public event eventhandler canexecutechanged; public bool canexecuteresult { { return canexecute; } set { if (canexecute != value) { canexecute = value; var canexecutechanged = canexecutechanged; if (canexecutechanged != null) canexecutechanged.invoke(this, eventargs.empty); } } } } }
if appcommands class defined in namespace.to.appcommads namespace, need declare in xaml:
xmlns:local="clr-namespace:namespace.to.appcommads" and use so:
command="{x:static local:appcommands.appcommand}"
Comments
Post a Comment