Wpf 在类库中使用资源字典

Wpf 在类库中使用资源字典,wpf,flowchart,Wpf,Flowchart,我正在我的应用程序中使用,但我想将其用作用户控件 要将应用程序转换为用户控件,我已更改了应用程序的唯一窗口: <Window x:Class="DiagramDesigner.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-name

我正在我的应用程序中使用,但我想将其用作
用户控件

要将
应用程序
转换为
用户控件
,我已更改了应用程序的唯一窗口:

<Window x:Class="DiagramDesigner.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="clr-namespace:DiagramDesigner"
    xmlns:c="clr-namespace:DiagramDesigner.Controls"
    WindowStartupLocation="CenterScreen"
    Title="Diagram Designer"
    Height="850" Width="1000">
  <Window.Resources>
    <ContextMenu x:Key="DesignerCanvasContextMenu">
      ...
    </ContextMenu>
  </Window.Resources>
  ...
</Window>

我在这里猜测,因为您的问题实际上没有显示任何可能导致问题的代码,但您可能需要使用
DynamicResource

{DynamicResource SolidBorderBrush}

您只能在非常特殊的情况下使用StaticResource。大多数情况下,您的性能会得到很大提升,但很容易出现无法使用的情况(这可能就是发生的情况)。

您说您从App.xaml获取了ResourceDictionary,但没有说您把它放在了哪里。更多关于资源字典、它们是什么以及如何使用它们的内容:(特别要看)哦,我把它放在了
UserControl
中。这可以在我粘贴的代码中看到。我会修正这个问题的,克莱尔,我的错。。。我没有仔细看代码。我编辑了你的标题。请看,“,共识是“不,他们不应该”。@J.A.I.L.-你的问题实际上与C#无关。如果你是用VB或F#开发的,什么都不会改变(问题或答案)。你猜对了!问题来自SolidBorderBrush的
StaticResource
声明。不,我必须将项目中的大部分(如果不是全部的话)
StaticResource
声明更改为
DynamicResource
。非常感谢。
<Trigger Property="IsMouseOver" Value="true">
   <Setter TargetName="Border" Property="Background" Value="{DynamicResource ToolbarSelectedBackgroundBrush}" />
   <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource SolidBorderBrush}" />
</Trigger>
{DynamicResource SolidBorderBrush}