Saturday, 12 March 2011
ResourceStrings Access Modifier
There is a small combobox at the top of the Resource editor that allows it to be changed.
Wednesday, 16 February 2011
MouseOver Triggers
<Window.Resources>
<Style TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Pink" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<TextBlock>Hello World</TextBlock>
</StackPanel>
Monday, 10 January 2011
ResourceStrings in XAML
In the end I chose to bind directly to the ResourceStrings resource using an x:Static
...
xmlns:local="clr-namespace:Sandstorm.PointOfSale.Modules.Tender.Resources"
...
<TextBlock Padding="20,0,0,0" Text="{Binding Source={x:Static local:ResourceStrings.V_Discount}, Mode=OneTime}" FontStyle="Italic"/>
Thursday, 20 August 2009
How to set a property to a DynamicResource reference in code
Our own example in XAML and C# looked like this:
itemsControlElement.SetResourceReference(ItemsControl.StyleProperty,
"POSDatesTimesButtonItemsControlStyle");
Sunday, 5 October 2008
Resource inheritance
If dictionaries being merged have a duplicate key, the last one wins (unlike the case of having duplicate keys in a single dictionary). Thus inheritance can be handled by the order in which the MergeDictionaries are loaded in the ResourceDictionary section… Start by loading the BASE, then the next down etc.. and it’ll override every time it meets a duplicate.
For reference – it’s on page 250ish in Martin's Unleashed book
Dynamic vs Static Resources :
DR means the resource is reapplied every time it changes.
The main difference between DR and SR is that any subsequent updates to the resource are reflected only to those elements that use DR.
SR and DR have different performance characteristics. DR requires more overhead than SR because of the extra overhead of tracking, while DR can potentially improve load time because SR are always loaded when the Window or Page loads, whereas the DR reference is only loaded when it’s actually used.
DR can also only set dependency properties whereas SR can be used almost anywhere
How are StaticResource and DynamicResource different
This was copied from http://wpfxaml.spaces.live.com/blog/cns!97DD5FD32788695B!142.entry for my own easy reference
Everyone one knows that StaticResource let’s one set a property of an element once.
If the Desktop Color is changed while the element’s application is running, the element keeps its original color:
<Button>
<Button.Background>
<SolidColorBrush Color="{StaticResource {x:Static SystemColors.DesktopColorKey}}" />
</Button.Background>
Hello
</Button>
On the other hand, if the element’s color is set using a DynamicResource, it changes when the Desktop Color changes:
<Button>
<Button.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.DesktopColorKey}}" />
</Button.Background>
Hello
</Button>
Why is that? The answer comes from the way these two Resource finders work:
1. StaticResource – Finds the resource given in by the ResourceDictionary key, and keeps the resource value;
2. DynamicResource – Finds the resource in the ResourceDictionary and keeps the key.
So, it is simple, really.
Since DynamicResource keeps the resource Key instead of the resource value, every event change fired from the resource lets the DynamicResource know that its value has changed.
This is why the DynamicResource reacts to the resource changes, while the StaticResource can’t know the resource has changed, since it only keeps the resource’s final value.