wpf Xaml:如何将自定义类公开给DataTemplate [英] wpf Xaml :how to expose custome class to DataTemplate
问题描述
我有一个用作数据源的类
I have a class which used as DataSource
namespace DictMainUI.Model
{
class SearchListItem:INotifyPropertyChanged
{
private string word;
private int checkamount;
............
public string Word
{
get { return this.word; }
set
{
this.word = value;
OnPropertyChanged(Word);
}
}
public int CheckAmount
{
get { return this.checkamount; }
set
{
if (value < 0)
{
throw new ArgumentException("Price must be positive");
}
this.checkamount = value;
OnPropertyChanged("CheckAmount");
}
}
.............
我想为要绑定到SearchListItem的ListboxItem定义一个日期模板.
我有一个ResourceDictionary,我想在此资源中定义DataTemplate.
I want to define a datetemplate for ListboxItem that I want to bind to SearchListItem.
I have a ResourceDictionary, I want to define DataTemplate in this resource.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
所以我认为我应该添加名称空间,以便向此ResourceDictionary公开SearchListItem属性.但是一旦我将其添加到resourcedictionary中,构建项目就失败了,没有任何消息,并且在运行它时,它显示了错误,提示:设置输出和程序集名称正确或如下所示的.code之类的代码(如我所说,显示错误)
so I think I should add namespace to in order to expose SearchListItem attributes to this ResourceDictionary. but once I add it to the resourcedictionary , building project is failed without any message, and when run it, it shows error it says:set output and assembly name correct or something like that .code shown below (which show error as I said)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:DictMainUI.Model"
>
将DictMainUI.Model命名空间添加到ResourceDictionary时出错.
我不知道为什么它不起作用,有人在这个问题上给我提建议吗?
it got wrong when I add DictMainUI.Model namespace to the ResourceDictionary.
I did not know why it dose not work,is there anyone give me a advice on that problem?
thanks in advance!
推荐答案
如果
namespace
在另一个程序集中,则还必须提供该程序集的名称,如下所示:
If the
namespace
is in another assembly, you have to provide the assembly''s name too, like the following:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:DictMainUI.Model;assembly=DictMainUI.Model"
>
我不知道项目发生了什么,经过多次修复后,我放弃了该项目,并构建了一个新项目并映射了custome类到资源词典y正在为此工作.
I don''t know what happened to the project, after tried to fix it many times I give up on that project , and build whole new project and mapping custome class to resourcedictionary is worked on this one.
这篇关于wpf Xaml:如何将自定义类公开给DataTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!