I have the following in a ResourceDictionary:
<Style x:Key="BasicStyle" TargetType="ContentControl">
<Setter Property="Width" Value="100" />
<Setter Property="Height" Value="30" />
</Style>
<Style x:Key="ButtonStyle" TargetType="Button" BasedOn="{StaticResource BasicStyle}">
<Setter Property="BorderBrush" Value="Orange" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="Foreground" Value="Orange" />
</Style>
I then tried to use the button style in MainPage.xaml like so:
...but at runtime I get, "Cannot find a Resource with the Name/Key ButtonStyle"
Do I have to formally introduce MainPage.xaml to the ResourceDictionary?
Does the ResourceDirectionary have to be referenced in MainPage, or from within App.xaml, or...???
So just what is the proper XML for Application.Resources inside App.xaml?
Using the idea from robertos below, after adding a resource dictionary to my project and naming it "GlobalStylesResourceDictionary.xaml", I added this to App.xaml:
<ResourceDictionary>
<ResourceDictionary Source="GlobalStylesResourceDictionary.xaml" />
</ResourceDictionary>
...so that my entire App.xaml is:
<Application x:Class="Photrax.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Photrax">
<Application.Resources>
<ai:TelemetryContext x:Key="ApplicationInsightsBootstrapper" xmlns:ai="using:Microsoft.ApplicationInsights"/>
<ResourceDictionary>
<ResourceDictionary Source="GlobalStylesResourceDictionary.xaml" />
</ResourceDictionary>
</Application.Resources>
</Application>
However, with this I get "Each dictionary entry must have an associated key."
Yet this comes [in]directly from Microsoft (robertos took the XAML he shows below from the ms page he references). So what's the problem?
You must reference the ResourceDictionary either in MainPage.xaml or App.xaml, using something like:
<Application.Resources>
<ResourceDictionary>
<!--other resources can be here-->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="rd1.xaml" />
<ResourceDictionary Source="rd2.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
More information: MSDN reference