2012-08-09 51 views
0

在我的WPF应用程序中,用户可以通过右键单击来选择一个命令。现在,我创建了一个按钮,并希望将此方法关联到按钮。没有访问所有方法(或引用XAML中的方法失败)?

我迄今所做的:

在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和命中空间但不是ing显示出来然后我试图键入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

但即使CLR的东西没有出现......如果你手动键入你的命名空间它工作吗? – 2012-08-09 17:44:58

+0

您可以找到有关如何格式化命名空间[这里](http://msdn.microsoft.com/en-us/library/ms747086.aspx)的信息。 – 2012-08-09 17:53:26

+0

@@胡安,我甚至都没有试图手动做它,它不喜欢它。 – 2012-08-09 17:55:35

回答

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> 
+0

是的它编译,但我不得不手动键入系统命名空间,但是,编译。 – 2012-08-09 18:42:03

+0

xmlns:custom =”clr-namespace:yournamespace; assembly = yourassembly“尝试这样的事情,并用您的数据替换。 让我知道 – 2012-08-09 22:54:44

相关问题