amit kohan
amit kohan

Reputation: 1618

Nested resources in XAML

I'm dealing with a nested situation in xaml such that I have a toolbar in it as

<Expander x:Name="expander1" Header="Controls" 
          Content="{StaticResource FC}" IsExpanded="True" />  

While static resource FC has been defined in another xaml file as in FC.xaml as

<tb:Toolbox x:Key="FC" ItemSize="70,70" SnapsToDevicePixels="True"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled">  

How can I use it in my code behind? please advise.

Upvotes: 1

Views: 516

Answers (2)

Andrei Gavrila
Andrei Gavrila

Reputation: 863

If I understand correctly, you want to use the toolbox FC resource in your code behind. You could use the FrameworkElement.FindResource using "FC" as key and casting the result to the Toolbox type.

If the resource FC is available to your windows/control it should work just fine.

Upvotes: 1

akjoshi
akjoshi

Reputation: 15772

Have you tried using it like this -

Toolbox toolbox = expander1.Content as Toolbox;

This should work; in case you want to access it from Resource Dictionary(your xaml file) then use FrameworkElement.FindResource as Andrei suggested.

Upvotes: 1

Related Questions