tags:

views:

43

answers:

2

I have defined a menu template which, in theory, should use the backgroundcolor of the "AppBackground" SoliColorBrush, defined in a separate file.

When in "debug mode", I use the following code to change that variable: this.Resources["AppBackground"] = new SolidColorBrush(Colors.DarkGreen);

This has the intended effect on the application background, however, it doesn't seem to have an effect on the custom menu design I have. I have tried to use both StaticResource and DynamicResource, without any luck. Is this a known issue, and is there a trick here?

Defined in ResourceDirectory:

<SolidColorBrush x:Key="AppBackground" Color="#003466"/>

Defined in a file:

 <Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}">
   <Setter Property="Template">
       <Setter.Value>
          <ControlTemplate TargetType="{x:Type MenuItem}">
              <Border x:Name="Border" BorderThickness="1">
                 <Grid Background="{Binding Source={StaticResource AppBackground}}">
+2  A: 

Havent seen that you marked that it works also not with DynamicBinding. I only looked at the code. Thats why I wrote my first answer:

Use DynamicBinding, that should work.

The real problem you wrapp the resource through a Binding. Remove this, as I wrote in my other post. Sorry the chaos with the multiple answers.

<Grid Background="{DynamicResource AppBackground}">

HCL
" I have tried to use both StaticResource and DynamicResource"
Will
Exactly, Dynamic doesn't cut it! I belive it has to do something with the "templates" property.
Sideshow Bob
Seems to work now! Thanks
Sideshow Bob
+2  A: 

It seems to be a typing error: Remove the {Binding... and it works:

<Grid Background="{DynamicResource AppBackground}"> 

The binding acts as a wrapper between the ressource and the destination and prevents the tracking of the changes.

HCL
Returns runtime error: "Cannot set propert on object '#FF003466' because it is in a read-only state. Code is run in "OnStartup" function, under 'public partial class App : Application'
Sideshow Bob
See my last edit...
HCL