Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Using Resources

 
 
Old 01-31-2006   #1 (permalink)
Erno


 
 

Using Resources

Hi!

From within code I can use FindResource() to find a resource identified by a
key. This way I attach the same ContextMenu to multiple, runtime generated
Visuals.

I really like the fact that the context menu is in its own Xaml file now, so
I figured it would be nice to have my main menu to reside in its own Xaml
file as well...

Suppose I used to have a DockPanel in my Window like this:

<DockPanel LastChildFill="True" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" Name="dockPanel1">

<Menu DockPanel.Dock="Top">
...
</Menu>

</DockPanel>

Now let's move the Menu to its own Xaml like this

<Menu x:Key="MainMenu" DockPanel.Dock="Top">
...
</Menu>

Now the following questions arises:

How do I refer to and insert from within the DockPanel the menu?

I consider DockPanel.Dock="Top" in my resourcedictionary menu very ugly (to
say the least). So I'd expect a contruction like this:

<DockPanel LastChildFill="True" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" Name="dockPanel1">

<Menu DockPanel.Dock="Top" resourcekey="MainMenu"/>
</DockPanel>

Anybody any idea?

Thanks!

Erno



My System SpecsSystem Spec
Old 01-31-2006   #2 (permalink)
Erno


 
 

Re: Using Resources

Nick,

I tried this:

<DockPanel Name="dockPanel1">
<Menu DockPanel.Dock="Top">
<StaticResource ResourceKey="MainMenu"/>
</Menu>
</DockPanel>

(<StaticResourceExtention> couldn't be nested in the DockPanel.)

But I still get the "Invalid value 'System.Windows.Controls.AccessText' for
property 'Header'.
Values derived from Visual or ContentElement cannot be set in a 'Template'."
message...

Thanks,

Erno

"Nick Kramer [MSFT]" <nkramer@ms.spam> wrote in message
news:u1hYmgiHGHA.3144@TK2MSFTNGP11.phx.gbl...
> <DockPanel>
> <StaticResourceExtension ResourceKey="foo"/>
>
>
> Where that second line is really just another syntax for {StaticResource
> foo}
>
> --
> -Nick Kramer [MSFT]
> http://blogs.msdn.com/nickkramer
>
> ---
> This posting is provided "AS IS" with no warranties, and confers no
> rights. Use of included script samples are subject to the terms specified
> at http://www.microsoft.com/info/cpyright.htm
>
>
> "Erno" <nospam> wrote in message
> news:OrV9T8gHGHA.3916@TK2MSFTNGP10.phx.gbl...
>> BTW: I tried Templated Controls and ran into the errormessage:
>>
>> Invalid value 'System.Windows.Controls.AccessText' for property 'Header'.
>> Values derived from Visual or ContentElement cannot be set in a
>> 'Template'.
>>
>> Erno
>>
>> "Erno" <nospam> wrote in message
>> news:uwJ7LsgHGHA.916@TK2MSFTNGP10.phx.gbl...
>>> Hi!
>>>
>>> From within code I can use FindResource() to find a resource identified
>>> by a key. This way I attach the same ContextMenu to multiple, runtime
>>> generated Visuals.
>>>
>>> I really like the fact that the context menu is in its own Xaml file
>>> now, so I figured it would be nice to have my main menu to reside in its
>>> own Xaml file as well...
>>>
>>> Suppose I used to have a DockPanel in my Window like this:
>>>
>>> <DockPanel LastChildFill="True" VerticalAlignment="Stretch"
>>> HorizontalAlignment="Stretch" Name="dockPanel1">
>>>
>>> <Menu DockPanel.Dock="Top">
>>> ...
>>> </Menu>
>>>
>>> </DockPanel>
>>>
>>> Now let's move the Menu to its own Xaml like this
>>>
>>> <Menu x:Key="MainMenu" DockPanel.Dock="Top">
>>> ...
>>> </Menu>
>>>
>>> Now the following questions arises:
>>>
>>> How do I refer to and insert from within the DockPanel the menu?
>>>
>>> I consider DockPanel.Dock="Top" in my resourcedictionary menu very ugly
>>> (to say the least). So I'd expect a contruction like this:
>>>
>>> <DockPanel LastChildFill="True" VerticalAlignment="Stretch"
>>> HorizontalAlignment="Stretch" Name="dockPanel1">
>>>
>>> <Menu DockPanel.Dock="Top" resourcekey="MainMenu"/>
>>> </DockPanel>
>>>
>>> Anybody any idea?
>>>
>>> Thanks!
>>>
>>> Erno
>>>

>>
>>

>
>



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
VPN / Local resources Vista networking & sharing
Not enough resources Vista hardware & devices
resources Vista hardware & devices
PCI to PCI Bridge not enough resources Vista hardware & devices
Best resources for Development? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46