1

In a ResourceDictionary file I want to alias the resource NavyBlueBrush as TopBrush to give the resource a logical meaning.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:globalResources="clr-namespace:GlobalResources">
    <SolidColorBrush x:Key="NavyBlueBrush" Color="#01354b"/>
        ...
    <StaticResourceExtension ResourceKey="NavyBlueBrush" x:Key="TopBrush"/>
        ...
</ResourceDictionary>

In the application I can use NavyBlueBrush just fine. But if I try to use TopBrush, it is not applied. What's wrong?

<Grid Background="{Binding Mode=OneWay, Source={StaticResource NavyBlueBrush}}">    --- Grid is colored
    ...
<Grid Background="{Binding Mode=OneWay, Source={StaticResourceExtension TopBrush}}" />    --- Grid IS NOT colored
blearyeye
  • 255
  • 4
  • 14
  • http://stackoverflow.com/questions/634069/redefine-alias-a-resource-in-wpf suggests that Source should be a `Source={StaticResource TopBrush}` instead of a `Source={StaticResourceExtension TopBrush}` – Eugene Podskal Jan 07 '17 at 19:54
  • I tried Background="{Binding Mode=OneWay, Source={StaticResource TopBrush}}", same result. – blearyeye Jan 07 '17 at 20:44
  • That question also discusses some issues with global resource dictionaries (see all answers). – Eugene Podskal Jan 07 '17 at 20:45
  • I tried the solution by Ruedi Steinmann. It works, but the limitation is that WPF designer doesn't show the effect of using the aliases; it's only seen at runtime. So, yes, it's a possibility. But it would be nice to be able to do it all in XAML ... – blearyeye Jan 07 '17 at 20:53

0 Answers0