gCan不再使用样式

时间:2015-11-12 21:37:21

标签: c# wpf xaml

编辑2:以下是该项目的link

编辑:不确定我的项目发生了什么,但似乎搞砸了大部分时间。获得多个错误,说明我的转换器的负载在命名空间中不存在,当它们发生时!

这里我有一个在XAML中定义的类的实例:

<Application x:Class="Test_Project.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Test_Project">
    <Application.Resources>
        <ResourceDictionary>
            <local:runtimeObject x:Key="runtimeVariables" />
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Styles/Generic.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

但它确实存在,如下所示!这随机突然搞砸了!

namespace Test_Project
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            //Startup
            Window main = new MainWindow();
            main.Show();
        }
    }

    /// <summary>
    /// Global values for use during application runtime
    /// </summary>
    public class runtimeObject : INotifyPropertyChanged
    {
    ....

不太确定这里出了什么问题,由于某些原因,现在我无法使用我已经制作的新ResourceDirectory。立即收到此错误:

  

类型或命名空间名称&#39;样式&#39;在命名空间中不存在   &#39; Test_Project&#39; (你错过了一个程序集引用吗?)

错误在以下行: 的 NotificationWindow.g.cs

using Test_Project.Styles;

NotificationWindow.xaml

<Window x:Class="Test_Project.Views.NotificationWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Test_Project.Views"
        mc:Ignorable="d"
        Title="Notification" Style="{StaticResource NotificationWindow}">
    <Grid RenderTransformOrigin="0,1" >
        <!-- Notification area -->
        <Border>
            <StackPanel Margin="20">
                <TextBlock>
                    Hello
                </TextBlock>
            </StackPanel>
        </Border>

        <!-- Animation -->
        <Grid.Triggers>
            <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
                            <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
                            <SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
                            <SplineDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
                            <SplineDoubleKeyFrame KeyTime="0:0:4" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>

        <Grid.RenderTransform>
            <ScaleTransform ScaleY="1" />
        </Grid.RenderTransform>
    </Grid>
</Window>

这是我的 App.xaml

<Application x:Class="Test_Project.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Test_Project">
    <Application.Resources>
        <ResourceDictionary>
            <local:runtimeObject x:Key="runtimeVariables" />
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Styles/Generic.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Generic.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Test_Project.Styles">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Buttons.xaml" /> <!-- All Button Styles -->
        <ResourceDictionary Source="Misc.xaml" /> <!-- All Misc Styles -->
        <ResourceDictionary Source="Notifications.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

在这里,您可以看到我的项目文件结构:

enter image description here

1 个答案:

答案 0 :(得分:0)

我进入了微软论坛,有人帮我找到了这个问题。当我创建ResourceDictionary时,它生成了一个本地标记,其名称空间为clr-namespace:namespacehere.Styles

这似乎使我的新窗口生成一个名为Window1.g.cs的文件,其中包含导致问题的行using namespacehere.Styles;

#pragma checksum "..\..\..\Views\NotificationWindow.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "922E7A4BDAE53DAC4A05221020498CA6"
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using PhotoManagement.Converters;
using PhotoManagement.Styles; //Error occurs here!
using PhotoManagement.Views;
using System;

所以我必须搜索整个解决方案并删除任何似乎导致问题的namespacehere.Styles引用,如下所示:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:PhotoManagement"
                    xmlns:Converters="clr-namespace:PhotoManagement.Converters">

之前有xmlns:local="clr-namespace:PhotoManagement.Styles"