I made two xaml resource files in themes folder
generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="themes/msofficeui.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
msofficeui.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:System.Windows.Resources.Libraries">
<Color A="#FF" R="#BF" G="#BF" B="#BF" x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ColorLibrary}, ResourceId=MSOLightGray}"/>
<Color A="#FF" R="#91" G="#91" B="#91" x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ColorLibrary}, ResourceId=MSOGray}" />
<Color A="#FF" R="#F9" G="#E1" B="#89" x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ColorLibrary}, ResourceId=MSOLightGold}" />
<Color A="#FF" R="#FF" G="#D8" B="#6C" x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ColorLibrary}, ResourceId=MSOGold}" />
<Color A="#FF" R="#38" G="#38" B="#38" x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ColorLibrary}, ResourceId=MSOBlack}" />
<LinearGradientBrush x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:BrushLibrary}, ResourceId=MSORibbonBackgroundGray}"
StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#FFBFBFBF" Offset="0" />
<GradientStop Color="#FF919191" Offset="1" />
</LinearGradientBrush>
<RadialGradientBrush x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:BrushLibrary}, ResourceId=MSOButtonBackgroundEnter}"
GradientOrigin = "0.5,1.02" Center="0.5,1.02" RadiusX="0.8" RadiusY="0.2">
<GradientStop Color="#FFFFFFFF" Offset="0" />
<GradientStop Color="#FFF9E189" Offset= "1" />
</RadialGradientBrush>
<RadialGradientBrush x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:BrushLibrary}, ResourceId=MSOButtonBackgroundPressed}" Center="0.5,1.5">
<GradientStop Color="#FFFFFFFF" Offset="0" />
<GradientStop Color="#FFFFD86C" Offset= "0.55" />
</RadialGradientBrush>
</ResourceDictionary>
when i tried to use one of the resources in my app, I got a message as follows:
Cannot locate resource 'themes/msofficeui.xaml'.
at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
at System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream()
at System.IO.Packaging.PackWebResponse.GetResponseStream()
at System.IO.Packaging.PackWebResponse.get_ContentType()
at MS.Internal.WpfWebRequestHelper.GetContentType(WebResponse response)
at MS.Internal.WpfWebRequestHelper.GetResponseStream(WebRequest request, ContentType& contentType)
at System.Windows.ResourceDictionary.set_Source(Uri value)
at System.Windows.Baml2006.WpfSharedBamlSchemaContext.<Create_BamlProperty_ResourceDictionary_Source>b__1c4(Object target, Object value)
at System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(Object instance, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
I changed the uri referred to msofficeui.xaml in generic.xaml to both absolute and relative pack Uris, but the same exception continued to be thrown out.
I put the stuff of msofficeui.xaml directly in generic without using MergedDictionaries, then everything goes fine. So it is definitely a Uri problem.
What's wrong with the uri? It has taken me a couple of hours. I tried every way I can imagine. Now I'm mad.....