WPF如果我将窗口和应用程序移动到visual studio的子文件夹中,为什么设计视图会失败

时间:2013-08-08 23:48:36

标签: wpf xaml resourcedictionary

    

<LinearGradientBrush x:Key="MaroonGradientBrush" EndPoint="0,1" StartPoint="0,0">
  <GradientStop Color="#FF0C0B0B" Offset="1"/>
  <GradientStop Color="#FFBF5656"/>
</LinearGradientBrush>

<Window 
  x:Class="GraphViewerWindow"
  RenderOptions.EdgeMode="Unspecified"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:DaedalusGraphViewer="clr-namespace:DaedalusGraphViewer"
  Title="Window1" Height="900" Width="900">
  <TextBox Background="{StaticResource MaroonGradientBrush}" />
</Window>

程序会打开一个带有正确渐变画笔的窗口。但是,设计视图仍然无法加载窗口,因为它无法找到maroongradientbrush。

编辑:

发现我的问题。正是这样:

How to move App.xaml and not to break designer?

但没有发布解决方案

1 个答案:

答案 0 :(得分:1)

你的XAML错了。这就是它无法正常工作的原因

以下列方式将这些内容放回App.xaml中:

<Application ...>
   <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
               <ResourceDictionary Source="ResourceDictionaries/GraphViewerBrushes.xaml" />
               <ResourceDictionary Source="ResourceDictionaries/GraphViewerTreeViewResources.xaml" />
               <ResourceDictionary Source="ResourceDictionaries/SignalScrollViewerResources.xaml" />
               <ResourceDictionary Source="ResourceDictionaries/ValidationErrorResources.xaml" />
               <ResourceDictionary Source="ResourceDictionaries/GraphViewerToolbarResources.xaml" />
               <ResourceDictionary Source="ResourceDictionaries/SavedResourcesIMightUse.xaml" />
            </ResourceDictionary.MergedDictionaries>
       </ResourceDictionary>
   </Application.Resources>
</Application>  

如果您将所有这些资源都放入应用程序的EACH UserControl中,您将创建一个可怕的记忆猪。

StaticResource应该可以正常工作。我在我的项目中这样做,从来没有遇到任何问题。即使您的资源存储在外部程序集(pack://applicaton等)

中也是如此