繁体   English   中英

WPF:类的数据模板

[英]WPF: Datatemplate For Class

我有这个XAML:

<UserControl x:Class="M_Cubed.Controls.TagEditor"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:classes="clr-namespace:M_Cubed.Classes">
    <UserControl.Resources>
        <DataTemplate DataType="{x:Type classes:TagEditorPic}">
            <ComboBox DataContext="{StaticResource PicTypes}"
                ItemsSource="{Binding}"/>
        </DataTemplate>
    </UserControl.Resources>
</UserControl>

我有这个C#:

namespace M_Cubed.Classes
{
     public class TagEditorPic : INotifyPropertyChanged
     {
          public TagEditorPic() { }
     }
}

我得到这个错误:

类型引用找不到名为“ TagEditorPic”的公共类型。

有什么建议么?

这是因为您没有实现INotifyPropertyChanged。 如果执行该操作,则控件将编译。

它找不到控件,因为它不能首先编译TagEditorPic类。 由于这不是可行的类,因此XAML解析器不知道该怎么做。

根据您的Visual Studio版本,您可能会获得陈旧的程序集。

尝试运行Build-> Clean Solution,然后运行Rebuild Solution。

如果这样不起作用,请尝试重新启动Visual Studio。

我决定只在数据模板上设置x:Key属性,然后将模板属性向前绑定到x:Key的StaticResource。 它对我来说很好。

同一程序集中的TagEditorPic类是什么? 否则,您需要像这样指定它:

xmlns:classes="clr-namespace:M_Cubed.Classes;assembly=myassembly"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM