walhore
Topic Author
Posts: 19
Joined: 25 Feb 2013, 17:24

Resource Dictionary

04 Dec 2014, 19:28

Hi Guys,

Sorry for the newbie question, but this is my first time using Resource Dictionaries with Noesis. I've read the documentation, but I'm not connecting the dots.

I've created a merged dictionary and put a few button styles in it. The buttons look fine in WPF, but default to the Noesis Style in XAML Player.

The merged dictionary is being set in app.xaml:
<Application.Resources>
	<!-- Resources scoped at the Application level should be defined here. -->
	<ResourceDictionary>
		<ResourceDictionary.MergedDictionaries>
			<ResourceDictionary Source="ResourceDictionaryButtonStyles.xaml"/>
		</ResourceDictionary.MergedDictionaries>
	</ResourceDictionary>
</Application.Resources>
And then I have my resource dictionary, ResourceDictionaryButtonStyles.xaml. These files are in the same directory as my other XAML files.

Ultimately, I'll have a few more resource dictionaries for button styles, colors and languages.

Again, sorry for the simple question and thanks!
Rob
 
User avatar
sfernandez
Site Admin
Posts: 3184
Joined: 22 Dec 2011, 19:20

Re: Resource Dictionary

05 Dec 2014, 16:59

Hi Rob,

The App.xaml is not used when you integrate NoesisGUI in your application.

To use resource dictionaries in your application you have two options:
  • Create a Theme dictionary that you can set globally to the application through IUISystem::SetTheme(). The styles and resources defined there will be used by all the xamls if no local resources are found. It is a good way to share resources and minimize memory consumption.
  • Or add the dictionary in the MergedDictionaries of any xaml you want to use it.
Inside XamlPlayer only the second option will be valid, because Theme dictionary is set by XamlPlayer application. So only resources defined in the xaml (directly or via MergedDictionaries) you are loading can be found. If you want to try the styles you defined in the ResourceDictionaryButtonStyles.xaml in XamlPlayer, you have to include it in the xaml you are working with:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Grid.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ResourceDictionaryButtonStyles.xaml">
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Grid.Resources>

    <!-- your UI design here -->

</Grid>
Hope this helps.
 
walhore
Topic Author
Posts: 19
Joined: 25 Feb 2013, 17:24

Re: Resource Dictionary

09 Dec 2014, 17:37

"Or add the dictionary in the MergedDictionaries of any xaml you want to use it."

Where does this go in the XAML? Can I assign it somewhere in resources for the entire XAML or do I need to assign it per element/object?

Thanks again. I really appreciate you guys being so responsive!!
 
walhore
Topic Author
Posts: 19
Joined: 25 Feb 2013, 17:24

Re: Resource Dictionary

09 Dec 2014, 21:29

Ok, figured this out.

Moved the </ResourceDictionary> tag to end of all styles and above </UserControl.Resources>. Seems to be happy again.
 
User avatar
jsantos
Site Admin
Posts: 4181
Joined: 20 Jan 2012, 17:18
Contact:

Re: Resource Dictionary

10 Dec 2014, 00:57

That is. The ResourceDictionary is normally included in the Resources property of the root element. That way it is available to all the elements of the XAML.

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests