0
我使用下面的代碼來創建資源字典樣式「類型引用無法找到類型」異常:爲什麼我得到,而在C#代碼指的ResourceDictionary
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Chart="clr-namespace:TestApp.Controls.Chart">
<Style x:Key="DefaultLabelStyle" TargetType="{x:Type Chart:LabelStyle}">
<Setter Property="LabelBrush">
<Setter.Value>
<SolidColorBrush Color="Red"/>
</Setter.Value>
</Setter>
<Setter Property="LabelFontSize" Value="12.0"/>
<Setter Property="Visibility" Value="False"/>
<Setter Property="OrientationAngle" Value="0"/>
<Setter Property="LabelPlacement" Value="Top"/>
<Setter Property="LabelOrientation" Value="Normal"/>
</Style>
,然後嘗試使用下面的代碼來使用它:
public static void LoadSkin()
{
var _skinDictionary = new ResourceDictionary { Source = new Uri("/Chart;component/Resources/DefaultSkin.xaml", UriKind.RelativeOrAbsolute) };
}
但其拋「類型引用無法找到類」異常,提的是,無法找到LabelStyle。但是LabelStyle是Chart中的一個公共類。
我在做什麼錯在這裏?
我想在這裏檢查其他線程有類似的問題,並設法使這些變化,
仍然不工作:(
請讓我知道你的建議.. !!
是在同一個組件設置爲XAML的'TestApp.ControlStyles.Chart'命名空間? – 2012-07-08 19:15:27
什麼樣的類是'LabelStyle'?這個名字暗示它也是一種風格,這會很奇怪。 [TargetType](http://msdn.microsoft.com/en-us/library/system.windows.style.targettype.aspx)必須指定從FrameworkElement或FrameworkContentElement派生的類型。 – Clemens 2012-07-08 19:29:18
您是否試圖添加已爲某些控件定義的樣式?如果是這樣,你需要這樣做: