Using XAML resource in view model

Viewed 12167

I have several resources declared in XAML markup and would like to access the resources in my view model. I could easily use something foo.Resources["resourceKey"] or findResource("") but that would mean that I would have to couple my XAML and C# code closely together. Not what I intended to do when I started using MVVM.

Is there a best practice or any way to use resources defined in the view in the view model?

Update:

The resources are mainly symbol definitions which are used to define the appearance of symbols in ESRI maps. For example this:

<esri:MarkerSymbol x:Key="SMS">
    <esri:MarkerSymbol.ControlTemplate>
        <ControlTemplate>
            <Ellipse x:Name="Element" Margin="-7,-7,0,0" Width="14" Height="14" Fill="Blue">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="SelectionStates">
                        <VisualState x:Name="Unselected" />
                        <VisualState x:Name="Selected">
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)" To="Green" Duration="00:00:0.25"/>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
            </Ellipse>
        </ControlTemplate>
    </esri:MarkerSymbol.ControlTemplate>
</esri:MarkerSymbol>

The symbols are added programatically to the map, though I need to access them in my view model.

3 Answers

You can get your application-wide xaml resources

Application.Current.Resources["ApplicationScopeResource"] = Brushes.White;
Related