Reputation: 690
I am using following code to Create a Style in Resource Dictionary:
<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>
and then trying to consume it using following code:
public static void LoadSkin()
{
var _skinDictionary = new ResourceDictionary { Source = new Uri("/Chart;component/Resources/DefaultSkin.xaml", UriKind.RelativeOrAbsolute) };
}
but its throwing "Type reference cannot find type" exception, mentioning that unable to find LabelStyle. But LabelStyle is a public class in Chart.
What I am doing wrong here?
I tried checking other threads here with similar problem and tried to make those changes,
still it doesn't works :(
Please let me know your suggestions..!!
Upvotes: 0
Views: 1038
Reputation: 128061
You cannot apply a Style to a type that is not derived from FrameworkElement or FrameworkContentElement. See the Remarks section in Style.TargetType.
Maybe your LabelStyle
class could simply get its property values from resources like this:
<ResourceDictionary ...
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:Double x:Key="LabelFontSize">12.0</sys:Double>
...
</ResourceDictionary>
Upvotes: 1