如何正确地引用来自XAML类 [英] How to properly reference a class from XAML
问题描述
OK,这是一个超级超级noob问题,一个我几乎不好意思问...
OK, this is a super super noob question, one that I'm almost embarrassed to ask...
我想在我的XAML文件中引用类。它是选择一个DataGrid列右侧的修改模板DataTemplateSelector。
I want to reference a class in my XAML file. It's a DataTemplateSelector for selecting the right edit template for a DataGrid column.
不管怎样,我已经写了类到我后面的代码,添加了本地命名空间的顶部在XAML之上,但是当我尝试从XAML引用类,它告诉我的班在当地的命名空间不存在。我必须失去了一些东西真的很简单,但我只是不明白它...
Anyway, I've written the class into my code behind, added the local namespace to the top of top of the XAML, but when I try to reference the class from the XAML, it tells me the class does not exist in the local namespace. I must be missing something really really simple but I just can't understand it...
下面是我的代码。
XAML:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tk="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:local="clr-namespace:CustomFields"
xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Class="CustomFields.MainWindow"
x:Name="Window"
Title="Define Custom Fields"
Width="425" Height="400" MinWidth="425" MinHeight="400">
<Window.Resources>
<ResourceDictionary>
<local:RangeValuesEditTemplateSelector>
blah blah blah...
</local:RangeValuesEditTemplateSelector>
</ResourceDictionary>
</Window.Resources>
C#:
C#:
namespace CustomFields
{
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
// Insert code required on object creation below this point.
}
}
public class RangeValuesEditTemplateSelector : DataTemplateSelector
{
public RangeValuesEditTemplateSelector(){
MessageBox.Show("hello");
}
}
}
任何想法我做错了什么?我想这应该是简单的1-2-3 ...
Any ideas what I'm doing wrong? I thought this should be simple as 1-2-3...
谢谢!
推荐答案
OK ......它突然开始工作。刚刚重建。
OK... it suddenly started working. Just had to rebuild.
这篇关于如何正确地引用来自XAML类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!