Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:49:59+00:00 2026-06-13T06:49:59+00:00

Advice: The code works fine, this question is about best practices of doing it.

  • 0

Advice: The code works fine, this question is about best practices of doing it.

In my project, the fill of the rectangle is a canvas that represents the state of an video, example, if the user click in play, the canvas needs to be changed to something like playing, is the video ends, the canvas needs to be changes to something like stopped. I have all of the canvas that represents this states in one resource dictionary.

My requirement is: i have a ResourceDictionary with a lot of resources, the resources looks like this

<Canvas Width="48" Height="48" Clip="F1 M 0,0L 48,0L 48,48L 0,48L 0,0" x:Key="appbar_add">
    <Path Width="24" Height="24" Canvas.Left="12" Canvas.Top="12" Stretch="Fill" Fill="{DynamicResource BlackBrush}" Data="F1 M 22,12L 26,12L 26,22L 36,22L 36,26L 26,26L 26,36L 22,36L 22,26L 12,26L 12,22L 22,22L 22,12 Z " />
</Canvas>
<Canvas Width="48" Height="48" Clip="F1 M 0,0L 48,0L 48,48L 0,48L 0,0" x:Key="appbar_alert">
    <Path Width="22.1402" Height="20.75" Canvas.Left="12.9299" Canvas.Top="14" Stretch="Fill" Fill="{DynamicResource BlackBrush}" Data="F1 M 24,14C 26,14 36,33 35,34C 34,35 14,35 13,34C 12,33 22,14 24,14 Z M 24,29C 23.1716,29 22.5,29.6716 22.5,30.5C 22.5,31.3284 23.1716,32 24,32C 24.8284,32 25.5,31.3284 25.5,30.5C 25.5,29.6716 24.8284,29 24,29 Z M 22.5,20L 23,28L 25,28L 25.5,20L 22.5,20 Z " />
</Canvas>
<Canvas Width="48.0067" Height="48.0067" Clip="F1 M 0,0L 48.0067,0L 48.0067,48.0067L 0,48.0067L 0,0" x:Key="appbar_alien">
    <Path Width="22.005" Height="16.0048" Canvas.Left="12.9999" Canvas.Top="16.9998" Stretch="Fill" Fill="{DynamicResource BlackBrush}" Data="F1 M 16.9999,16.9998L 19.0002,16.9998L 19.0026,19.0027L 21.0002,18.9998L 21.0029,21.0029L 27.0038,21.0029L 26.9999,18.9998L 28.9999,18.9998L 28.9999,16.9998L 31.0002,16.9998L 31.0002,19.0001L 29.0002,19.0001L 29.0041,21.0029L 31.0043,21.0029L 31.0043,23.0032L 33.0046,23.0032L 33.0046,25.0035L 31.0043,25.0035L 31.0001,31.0001L 29.0001,31.0001L 29.0001,33.0001L 25.0035,33.0046L 25.0035,31.0043L 28.9999,30.9999L 29.004,28.0039L 19.0026,28.0039L 19.0026,31.0043L 17.0024,31.0043L 16.9999,25.0001L 15.0002,25.0001L 15.0002,29.0001L 12.9999,29.0001L 12.9999,24.9998L 14.9999,24.9998L 14.9999,22.9998L 16.9999,22.9998L 17.0024,21.0029L 19.0026,21.0029L 18.9999,19.0001L 16.9999,19.0001L 16.9999,16.9998 Z M 33.0046,25.0035L 35.0049,25.0035L 35.0049,29.0041L 33.0046,29.0041L 33.0046,25.0035 Z M 19.0026,31.0043L 23.0032,31.0043L 23.0032,33.0046L 19.0026,33.0046L 19.0026,31.0043 Z M 19.0026,23.0032L 19.0026,25.0035L 21.0029,25.0035L 21.0029,23.0032L 19.0026,23.0032 Z M 27.0038,23.0032L 27.0038,25.0035L 29.004,25.0035L 29.004,23.0032L 27.0038,23.0032 Z " />
</Canvas>
...

I want to open this resource, find one resource by name, and apply this resource to a fill of a rectangle. Actually i am doing the following:

 private void ChangeFill()
    {
        Collection<ResourceDictionary> appResources = Application.Current.Resources.MergedDictionaries;

        if (Application.Current.Resources.MergedDictionaries.Count > 1)
        {
            ResourceDictionary recIcones = appResources.Where(r => r.Source.OriginalString == "Resources/Icons.xaml").FirstOrDefault(); // get the properly resource dictionary

            if (recIcones != null)
            {
                Canvas x = (Canvas)recIcones["appbar_add"]; // find a espicified resource by name
                VisualBrush vBrush = new VisualBrush(x);
                rctParado.Fill = vBrush; // apply it to the rectangle
            }
        }
    }

This works fine, the question is:
Is this the better way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:50:00+00:00Added an answer on June 13, 2026 at 6:50 am

    Just call FindResource on something in your visual tree. This will automatically search for a resource, recursing up the visual tree as necessary until it finds it (including looking in your app-level resources). If you only want to search in the application’s resources, use the FindResource method on the Application object.

    As for dynamically assigning the resource, it’s likely you could achieve the same thing more cleanly and elegantly via data binding. That is, bind the Canvas‘ Style property to whatever it is that instigates the change in style, and use a converter to do the resource lookup. It’s hard to be more specific without the full details of your scenario.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to ask you about some advices about this code. It works,
I have a struct that implements some interface . This works fine until I
I need your advice on this piece of code: the table fields options[0], options[1]
I have this div in my code: <div id=advice class=validation-advice style=>some text here</div> Now,
Any advice how to console.log the element that fired an hover action? This is
This js-code works in safari on my pc, but not on a ipod touch
This is a question about the use of type classes in Haskell. I get
Please advise.. In the following code(Tested. Will work fine) public class Exp_Test { public
Edite: refined the code according to advice in comments but still no luck Update:
I can't get the code below to compile (see errors). Advice on correction would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.