I have a file (icons.xaml) that I added as a file in the Resources of my project. The file content is given below:
Icons.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<VisualBrush x:Key="Bucket"
Stretch="Uniform">
<VisualBrush.Visual>
<Viewbox Stretch="xxxx">
<Canvas Width="xxxxx"
Height="xxxx"> and so on...
Icons.xaml file's properties in vs 2017
Now, I want to consume the VisualBrush mentioned above, in my XAML (View) code directly. The lines are given below:
XAML Code (View)
<Setter Property="Icon">
<Setter.Value>
<Rectangle Fill="{Binding Bucket, Source={x:Static resx:Resources.Icons}}"/>
</Setter.Value>
</Setter>
The "resx" namespace is defined as:
xmlns:resx="clr-namespace:MyProjectNamespace.Properties"
When I run my project I cannot see my icons being binded to the rectangle's fill property and I am getting some xaml intellisense error which is "Cannot resolve property "Bucket" in the context of type "string".
Objective: I want to use the visualbrush key directly in the XAML in my Rectangle's Fill property in my View code.
Note: I have a restriction that I cannot use the code in the view which is given below, I cannot use <ResourceDictionary>
tab in the xaml code.
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyProjectNamespace;component/Resources/Icons.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Am I following the right approach regarding my objective or should I change this approach?
I have seen the methods that are used here in this answer but none of them are working Get values from *.resx files in XAML