How to Access a 'Key' of a Resource Dictionary ?

Using (or providing) Microsoft.NET Classes

How to Access a 'Key' of a Resource Dictionary ?

Postby PGilbert on Sat Oct 15, 2011 10:52 pm

If you save the following Xaml into a variable called 'dic':

Code: Select all
<ResourceDictionary
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

   <SolidColorBrush x:Key="ItemNormalBorderBrush" Color="#8C8E94"/>
   <SolidColorBrush x:Key="ItemNormalBackgroundBrush" Color="#FFE6E6E6"/>
   <SolidColorBrush x:Key="ItemHotBorderBrush" Color="#FF5CACFF"/>
   <SolidColorBrush x:Key="ItemHotBackgroundBrush" Color="#FFC2E0FF"/>
   <SolidColorBrush x:Key="ItemSelectedBorderBrush" Color="#FF3399FF"/>
   <SolidColorBrush x:Key="ItemSelectedBackgroundBrush" Color="#FF99CCFF"/>
   <SolidColorBrush x:Key="ItemDisabledBorderBrush" Color="#FFC9C7BA"/>
   <SolidColorBrush x:Key="ItemDisabledBackgroundBrush" Color="#F4F4F4"/>
   <SolidColorBrush x:Key="ItemDisabledForegroundBrush" Color="#FF808080"/>
</ResourceDictionary>


than you get the corresponding ResourceDictionary object doing:

      ⎕USING←('System.Windows.Markup,WPF/PresentationFramework.dll')
rDic←XamlReader.Parse(⊂dic)


than if you try to obtain a resource using a key like:

      rDic.Item(⊂'ItemNormalBackgroundBrush')


it does not work (NONCE ERROR). My question is: What is the proper way to extract a resource using a key from a resource dictionary object ?

Thanks
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to Access a 'Key' of a Resource Dictionary ?

Postby JohnD|Dyalog on Mon Oct 17, 2011 8:00 am

The issue here is that Item is defined as a property and Dyalog presents that as an indexable array, and allows non-numeric indexers on the property.

So, you should use:

rDic.Item[⊂'ItemNormalBackgroundBrush']

Note that you still need to enclose the character vector.

Best Regards,
John Daintree.

P.S. I've not tested this specific solution.
User avatar
JohnD|Dyalog
 
Posts: 74
Joined: Wed Oct 01, 2008 9:35 am

Re: How to Access a 'Key' of a Resource Dictionary ?

Postby PGilbert on Mon Oct 17, 2011 1:54 pm

Many Thanks John, it worked.
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada


Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest