在我的WPF应用程序中,用户可以通过右键单击来选择命令。现在,我创建了一个按钮,并希望将此方法与按钮相关联。
到目前为止我做了什么:
在XAML文件中,我有:
<Button Content="Run Compare" Command="{x:Static RunCompare_Exectued}"></Button>
然后在ResourceDirectory部分中,我试图提供对我的文件的引用,将方法保持为
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:myMethods="**Nothing Comes up here!!!**"
>
通常我会按住 Ctrl并点击空格栏但没有显示任何内容然后我尝试输入clr-namespace:FileNameConatiningMethod ...但我收到的错误是:
未定义的CLR命名空间。 'clr-namespace'URI是指未包含在程序集中的名称空间'Application.Commands'。
任何帮助将不胜感激。
感谢。
编辑:
我可以访问其中一个有方法A和B的文件,但是,我无法访问不同源文件中的方法C和D.通过在XAML文件的根标记中添加命名空间,这不应该没问题吗?
假设我的命名空间是ABC,所以我有:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:ABC">
答案 0 :(得分:0)
请检查一下我在MSDN找到的方法。
还请检查您的代码是否正在编译,并且没有程序集引用冲突。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<!-- String resource that can be localized -->
<system:String x:Key="localizedMessage">en-US Message</system:String>
</ResourceDictionary>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="StringResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>