c# - WPF - Name doesn't exist in namespace -
i having namespace issue while trying implement custom bindings in wpf. getting error 'the name 'customcommands' not exist in namespace 'clr-namespace:graphicsbook;assembly=testbed2d".
in xaml have:
<window x:class="graphicsbook.window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:k="clr-namespace:graphicsbook;assembly=testbed2d" title="window1" <window.commandbindings> <commandbinding command="k:customcommands.addcircle" canexecute="addcirclecommand_canexecute" executed="addcirclecommand_executed"></commandbinding> </window.commandbindings> <menu> <menuitem header="add"> <menuitem command="k:customcommands.addcircle" /> </menuitem> </menu>
and customscommand.cs file within project folder. within file is:
namespace graphicsbook { public partial class customcommandsample : window { public customcommandsample() { ... } private void addcirclecommand_canexecute(object sender, canexecuteroutedeventargs e) { e.canexecute = true; } } public static class customcommands { public static readonly routeduicommand addcircle = new routeduicommand ( "addcircle", "addcircle", typeof(customcommands), new inputgesturecollection() { new keygesture(key.f4, modifierkeys.alt) } ); } }
the error comes line 'menuitem command="k:customcommands.addcircle"'.
any help much appreciated!!
your xml/clr namespace mapping wrong: have k
aliasing graphicsbook
, customcommands
declared in graphicsbook.assignment
.
you can seek using {x:static k:customcommands.addcircle}
instead of k:customcommands.addcircle
.
c# wpf namespaces undefined
No comments:
Post a Comment