Hello,
I'm developing an Extension SDK which offers a Page (the "main"-entry point for the integrator) with several static resources.
The resources I am using are defined in a separate "DefaultStyles.xaml" ResourceDictionary file.
Right now the UI Designer doesn't show anything because when opening the page with the Visual Studio UI Designer, all the StaticResources usages cannot be found.
I know that this is because the ResourceDictionary itself doesn't get loaded from within the Page, instead I'm loading it in the App.xaml which uses the SDK later and to allow to override the defined StaticResources. (By the way... when I try to load the ResourceDictionary inside <Page.Resources> to see all the stuff in the UI Designer the App crashes when initializing its components during debugging and navigating to the page)
Is there any other possibility to allow the integrator to customize the Page (besides of implementing a huge bunch of Dependency Properties or importing the DefaultStyles.xaml and overriding its defined Key Resources, like I'm doing right now)?
Here a simple sample:
I have two projects: the App and the SDK
SDK
- MainPage.xaml (e.g. BackgroundColorBrush is defined in DefaultStyles.xaml)
<Page
x:Class="xyzmo.ModernUiFatClient.Sdk.MainPage"
xmlns="http://ift.tt/w9rHWX;
xmlns:x="http://ift.tt/zZkFEV;
xmlns:d="http://ift.tt/PuXO1J;
xmlns:mc="http://ift.tt/R4RR6u;
xmlns:sdk="using:xyzmo.ModernUiFatClient.Sdk"
xmlns:utilities="using:xyzmo.ModernUi.Sdk.Utilities"
xmlns:xaml="using:xyzmo.UniversalSdk.Utilities.Xaml"
mc:Ignorable="d"
x:Name="PageRoot"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Loaded="OnMainPageLoaded"
SizeChanged="MainPage_SizeChanged">
<Page.Resources>
<utilities:LocalizationHelper x:Key="LocalizationHelper" />
<xaml:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</Page.Resources>
<Grid Background="{StaticResource BackgroundColorBrush}" Visibility="{Binding IsPageLoaded, Converter={StaticResource BooleanToVisibilityConverter}}">
<!-- CONTENT HERE -->
</Grid>
</Page>
- DefaultStyles.xaml
<ResourceDictionary
xmlns="http://ift.tt/w9rHWX;
xmlns:x="http://ift.tt/1idQEwn;
<SolidColorBrush x:Key="BackgroundColorBrush" Color="Pink" />
</ResourceDictionary>
App
- App.xaml (the Page from the SDK is used in the OnLaunched method in the code behind)
<Application
x:Class="xyzmo.SIGNificant.SignatureCapture.App"
xmlns="http://ift.tt/w9rHWX;
xmlns:x="http://ift.tt/zZkFEV;
xmlns:xaml="using:xyzmo.UniversalSdk.Utilities.Xaml"
RequestedTheme="Light">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Sdk/DefaultStyle.xaml"/>
<ResourceDictionary>
<!-- BackgroundColorBrush from DefaultStyles.xaml gets overridden here -->
<SolidColorBrush x:Key="BackgroundColorBrush" Color="Green" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
I know this works but I don't feel very comfortable with this... since it is always required to import the DefaultStyles.xaml inside the App's code. Otherwise the StaticResources won't be found.
Thank you very much for your help upfront!
Daniel
No comments:
Post a Comment