我在我的應用程序中使用this (excellent) flowchart diagram designer,但我想將它用作UserControl
。在類庫中使用資源字典
要將Application
轉換爲UserControl
我已經改變了應用程序擁有的唯一窗口:
<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>
到用戶控件:
<UserControl x:Class="DiagramDesigner.DiagramDesignerWPFControl"
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"
Height="850" Width="1000">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
...
</ResourceDictionary.MergedDictionaries>
<ContextMenu x:Key="DesignerCanvasContextMenu">
...
</ContextMenu>
</ResourceDictionary>
</UserControl.Resources>
...
</UserControl>
我把ResourceDicctionary
從App.xaml
內容並將其添加到控件中。然後我刪除App.xaml
文件,因爲它不能用於編譯Class Library
。
我的問題是:
當我添加新User Control
到WPF窗體在另一個項目中,我可以運行新的應用程序,我可以添加圖表組件和移動它們,但是當我加入/鏈接下列異常提出:
找不到名爲'{SolidBorderBrush}'的資源。資源名稱區分大小寫。
我在做什麼毛病我User Control
資源或自己的位置?接受答案後
版:
復活的例外還指出的線,其中 '{SolidBorderBrush}' 被調用。我最初並沒有把它放在這個問題上,因爲這是一個電話而不是一個聲明。這是一段代碼鏈接的異常:
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ToolbarSelectedBackgroundBrush}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource SolidBorderBrush}" />
</Trigger>
你說你從App.xaml獲取了ResourceDictionary,但是你沒有說你把它放在哪裏。有關資源字典的更多信息,它們是什麼以及如何使用它們:http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/03/creating-and-consuming-resource-dictionaries-in-wpf- and-silverlight.aspx(特別參見[資源在不同範圍聲明](http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/03/creating-and-consuming-resource-dictionaries-in -wpf-and-silverlight.aspx#resources)) – JDB
哦,我把它放在'UserControl'中。在我粘貼的代碼中可以看到。我會解決這個問題,以更多的克萊爾。 –
我的不好...我沒有仔細查看代碼。 – JDB