【问题标题】:Create Failed Style to my custom type (WPF)为我的自定义类型(WPF)创建失败的样式
【发布时间】:2013-11-29 08:07:20
【问题描述】:

我在将样式应用于自定义类型时遇到了问题。在下面的代码中。我制作了一个名为“MyListView”的扩展列表视图类型,它是从 Inventory.Interface 引用的。 为此创造了风格。它在调试时间完美显示。但是在运行时它会显示这样的错误

'未能从文本'man:MyListView' 创建'Type'。'行号“8”和行位置“12”。

为什么会来,这是怎么回事。

<ResourceDictionary 
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:src="clr-namespace:System;assembly=mscorlib"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:man="clr-namespace:Inventory.Interface"
                >
<Style TargetType="{x:Type man:MyListView}">
     <Setter Property="BorderBrush" Value="#FFDFDFE2"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Background" Value="#faf2f2"/>
      </Style>
</ResourceDictionary>

【问题讨论】:

  • 您的类型MyListView 是否存在于其他程序集中?如果是这样,请指定程序集。例如xmlns:man="clr-namespace:Inventory.Interface;assembly=MyOtherAssembly"。以及“完美地显示调试时间”是什么意思。但是在运行时...'?你的意思是编译时间而不是调试时间?
  • 非常感谢......它正在工作......
  • 发布解决方案(对您有用)作为答案。

标签: .net wpf wpf-controls wpf-4.0


【解决方案1】:
<ResourceDictionary 
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:src="clr-namespace:System;assembly=mscorlib"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:man="clr-namespace:Inventory.Interface;assembly=Inventory"
                >
<ObjectDataProvider x:Key="date" ObjectType="{x:Type src:DateTime}"/>
<Style TargetType="{x:Type man:MyListView}">
    <Setter Property="BorderBrush" Value="#FFDFDFE2"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="Background" Value="#faf2f2"/>
</Style>
</ResourceDictionary> 

【讨论】:

  • 用几句话来解释您的解决方案将使遇到同样问题的用户受益。另外,请尽可能接受这个答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-11
  • 1970-01-01
相关资源
最近更新 更多