Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type reference cannot find type named '{clr-namespace:xxx}ClassName on MergedDictionary

I'm received the exception Type reference cannot find type named '{clr-namespace:Dashboard.View}DashBoardColors at runtime.

I have a static class with my colors:

namespace Dashboard.View
{
    public static class DashBoardColors
    {
        public static readonly Color TargetColor = Color.FromRgb(200, 240, 255);
        public static readonly SolidColorBrush Red = new SolidColorBrush(Color.FromRgb(255, 0, 0));
        public static readonly SolidColorBrush Stale = new SolidColorBrush(Color.FromRgb(200, 200, 200));
        public static readonly SolidColorBrush Target = new SolidColorBrush(TargetColor);
        public static readonly SolidColorBrush Dragging = new SolidColorBrush(Color.FromRgb(200, 255, 200));
        public static readonly SolidColorBrush Good = Dragging;
    }
}

My resource dictionary:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:view="clr-namespace:Dashboard.View">

    <Style x:Key="AnimatedSwitch" TargetType="{x:Type ToggleButton}">
        <Setter Property="Foreground" Value="Silver" />
        <Setter Property="Background" Value="Silver" />
        <Setter Property="BorderBrush" Value="Silver" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleButton">
                    <Viewbox Stretch="Uniform" Width="40">
                        <Canvas Name="Layer_1" Width="20" Height="20">
                            <Ellipse  Canvas.Left="0" Width="20" Height="20" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="0.5"/>
                            <Ellipse  Canvas.Left="15" Width="20" Height="20" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="0.5"/>
                            <Border Canvas.Left="10" Width="15" Height="20" Name="rect416927" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0.5,0,0.5"/>
                            <Ellipse x:Name="ellipse"  Canvas.Left="0" Width="20" Height="20" Fill="White" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="0.3">
                                <Ellipse.RenderTransform>
                                    <TranslateTransform X="0" Y="0" />
                                </Ellipse.RenderTransform>
                                <Ellipse.BitmapEffect>
                                    <DropShadowBitmapEffect Softness="0.1" ShadowDepth="0.7" Direction="270" Color="#BBBBBB"/>
                                </Ellipse.BitmapEffect>
                            </Ellipse>
                        </Canvas>
                    </Viewbox>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.15" 
                                                          Storyboard.TargetName="ellipse"  
                                                          Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" 
                                                          To="{x:Static view:DashBoardColors.TargetColor}" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard FillBehavior="Stop">
                                        <ColorAnimation Duration="0:0:0.3" 
                                                            Storyboard.TargetName="ellipse"  
                                                          Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" 
                                                            To="White" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

And my usage within the usercontrol:

Included the namespace:

xmlns:view="clr-namespace:Dashboard.View"

Merged the dictionary:

<UserControl.Resources>
    <ResourceDictionary x:Key="Styles">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/Dashboard;component/View/Styles/AnimatedStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

Applied the style:

<ToggleButton  Style="{StaticResource AnimatedSwitch}" Height="20" x:Name="DateSelectToggle" />

The problem is in setting the following:

To="{x:Static view:DashBoardColors.TargetColor}"
like image 755
MattC Avatar asked Sep 29 '16 11:09

MattC


1 Answers

Oops,

I had the build action on View/Styles/AnimatedStyles.xaml set to resource which means that namespace needed to include the assembly, if it is not current:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:view="clr-namespace:Dashboard.View;assembly=Dashboard">

Or set the build action to Page and now it works.

like image 129
MattC Avatar answered Oct 24 '22 04:10

MattC