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 6848543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:52:52+00:00 2026-05-27T00:52:52+00:00

I have a customized WPF control that is derived from UserControl. In the Resources

  • 0

I have a customized WPF control that is derived from UserControl. In the Resources section in my XAML file I have several templates and styles defined for the items that will be displayed on my custom control.

Here is a definition for one of my styles to draw an downward pointing arrow.

    <Style x:Key="ArrowStyle" TargetType="Path">
        <Setter Property="Margin" Value="4"/>
        <Setter Property="Stretch" Value="Uniform"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="Data" Value="M 0 0 L 5 5 L 10 0 Z"/>
        <Setter Property="Fill" Value="{DynamicResource FormText}"/>
    </Style>

So, I have a custom buttom object that is derived from button. Basically it is a small square button that displays the arrow. In my constructor for my custom button I have the following code.

        Path Arrow = new Path();
        Arrow.Style = TryFindResource("ArrowStyle") as Style;

However, the call to TryFindResource fails indicated that it cannot location the resource. If I move the defined style into App.xaml it find it, but not when it is a custom control resource.

What am I doing wrong or missing?

Update

The custom button that I am calling TryFindResource for does reside on the custom user control. However, since I am calling TryFindResource in the constructor of the custom button it will not actually reside on the custom user control at the time TryFindResource is called. After the custom button is created it will be added to the custom user control. Perhaps there is a different way or place to put the TryFindResource so that it is called after the button belongs to the control.

  • 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-05-27T00:52:53+00:00Added an answer on May 27, 2026 at 12:52 am

    TryFindResource traverses the logical tree upward, to the parent element until the root element is reached.

    Then application resources are checked. That is the one you put in the second try, and worked because it was found there.

    So when you say “TryFindResource(“ArrowStyle”), it searches the arrow style on its parent elements up to its window resources and then application resources (global resources). When you call it from your custom button object, it can’t find it because your ArrowStyle resource do not satisfy the conditions above.

    You need to call it on your “customized WPF control that is derived from UserControl” or descendants of it.

    I think if you can’t make it work just move it to application resources or add a resource dictionary to your application resources with all global resources (styles):

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="....Your resources.xaml"/>
                <ResourceDictionary Source="....Your resources.xaml"/>
                <!-- Place further resources here -->
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF CustomControl that is derived from ComboBox and I'm trying to
We are developing a customized installer using Wix and Wpf. We have developed some
We have a lot of customized spreadsheet solutions that are being used and we
I have to develop a customized tab control and decided to create it with
I have an application that has a list of buttons and has customized tooltips.
I have panel that I have customized. I use it to display text. But
I am writing a WPF control that subclasses a Button. I then provide a
I have customized the contextual menu for my Cocoa application such that only certain
I have customized UITableViewCell (Static Content Loaded from nib). This cell contains one UILable
I am new to WPF and I have a doubt in modifying a control.

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.