1

So basically what I am trying to do is set a DynamicResource via code using the MVVM pattern.

Those are my resources:

<SolidColorBrush x:Key="UserGroupUserBrush" Color="Transparent"/> <SolidColorBrush x:Key="UserGroupSetterBrush" Color="Yellow"/> <SolidColorBrush x:Key="UserGrougShiftLeaderBrush" Color="{StaticResource ZFBlueColor}"/> <SolidColorBrush x:Key="UserGroupTeamLeaderBrush" Color="Black"/> 

Right here I want to set the resource:

<Ellipse DataContext="{vw:AdapterBinding UserManagementAdapter}" Fill="{DynamicResource UserGroupSetterBrush}" Height="20" Width="20" Margin="0,0,5,0"/> 

So lets say I want to change the resource "UserGroupSetterBrush" to "UserGroupUserBrush" in my code. What is the correct way to do this using the MVVM pattern?

1 Answer 1

2

What is the correct way to do this using the MVVM pattern?

In the code-behind of some view or some view-related class. Resources and brushes are part of the view only. The view model doesn't know nor care about these at all so there is basically no difference att all using or setting resources between a MVVM and a non-MVVM application.

The view model should not change the Fill property of an Ellipse. It may change a source property that the Fill property is bound to, but then you shouldn't set the property using a DynamicResource but bind it to a Brush source property of the view model and set this one in the view model.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.