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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:55:51+00:00 2026-05-31T23:55:51+00:00

I have a user control and it uses resource dictionaries. In that user control,

  • 0

I have a user control and it uses resource dictionaries. In that user control, there is another user control which uses same resource dictionaries.what I want to know is whether wpf actually loads it twice and if yes, is there any perfomance impact. Is there any better way to do this.

Thanks in advance.

  • 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-31T23:55:52+00:00Added an answer on May 31, 2026 at 11:55 pm

    Interesting question. I was intrigged enough to investigate. It appears that WPF loads a new ResourceDirectionary (and all resources defined and the dictionary which are used) for each appearance of element.

    Take a look at the following code:

    ViewModel:

    public class Person
    {
        public string name { get; set; }
        public int age { get; set; }
        public Person() { }
    }
    

    Resource (Dictionary1.xaml):

    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:so="clr-namespace:SO"
        >
        <so:Person x:Key="m" name="Methuselah" age="969" />
    </ResourceDictionary>
    

    View:

    <Window
        x:Class="SO.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:so="clr-namespace:SO"
        Height="200" Width="300"
        Title="SO Sample"
        >
        <Window.Resources>
            <ResourceDictionary Source="Dictionary1.xaml" />
        </Window.Resources>
    
        <StackPanel DataContext={StaticResource m}>
            <UserControl>
                <UserControl.Resources>
                    <ResourceDictionary Source="Dictionary1.xaml" />
                </UserControl.Resources>
                <TextBlock x:Name="inner" DataContext="{StaticResource m}" Text="{Binding Path=name}" />
            </UserControl>        
            <TextBlock x:Name="outer" Text="{Binding Path=name}" />        
            <Button Click="Button_Click">Change</Button>        
        </StackPanel>
    </Window>
    

    Put a breakpoint at the Person() constructor and notice the object is instantiated twice. Or, make Person implementing INotifyPropertyChange, and add the following code for Button_Click:

    private void Button_Click( object sender, RoutedEventArgs e ) {
        Person innerPerson = this.inner.DataContext as Person;
        Person outerPerson = this.outer.DataContext as Person;
        innerPerson.name = "inner person";
        outerPerson.name = "outer person";
    }
    

    If you want to have a single instance of each resource, have the reousrces in the element of app.xaml file.

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

Sidebar

Related Questions

I have written a WPF user control that uses Tahoma as a font to
I have web user control A that uses another web user control B. Inside
I have a WPF application which uses a WPF user control. The user control
I have a user control which uses objects as inner properties (some code is
i have user control, which i render on several views. i want to show
I have an ASP.NET user control that is used in another use control. The
I have a user control...and the base page(s) which uses this user control has
I have a user control that uses the standard if(!IsPostBack){//initialize myself} paradigm to avoid
I have a simple custom user control that uses jqGrid. the control is as
OK, so I have a user control which uses values from an underlying business

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.