5

実行時に例外を受け取りましたType reference cannot find type named '{clr-namespace:Dashboard.View}DashBoardColors

私は自分の色を持つ静的クラスを持っています:

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;
    }
}

私のリソース ディクショナリ:

<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>

そして、ユーザーコントロール内での私の使用法:

名前空間が含まれています:

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

辞書をマージしました:

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

スタイルを適用しました:

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

問題は、次の設定にあります。

To="{x:Static view:DashBoardColors.TargetColor}"
4

1 に答える 1

7

おっとっと、

リソースに設定されたビルドアクションがありましたView/Styles/AnimatedStyles.xaml。これは、名前空間が最新でない場合、アセンブリを含める必要があることを意味します。

<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">

または、ビルド アクションを に設定すると、Page機能するようになりました。

于 2016-09-29T11:37:11.697 に答える