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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:57:15+00:00 2026-05-18T06:57:15+00:00

Is there a way to pass parameters to a resource dictionary? I think that

  • 0

Is there a way to pass parameters to a resource dictionary? I think that I can attach a code behind for the purpose of specifying event handlers, but unfortunately, I also need to access a reference to the parent control from the event handlers. The codebehind, I believe, can be attached by specifying an x:Class attribute for the resource dictionary in xaml, and then creating a class in the same folder, the filename for which is something like [resource dictionary name].xaml.cs.

The purpose is to seperate the code for four hierarchical data templates that I’m using in a single treeview control. The xaml for the treeview is getting a bit long and ugly to look at, so I was hoping to break it down into four resource dictionaries. Any thoughts are welcome!

Andrew

  • 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-18T06:57:15+00:00Added an answer on May 18, 2026 at 6:57 am

    Resource dictionaries sound like a slightly peculiar way to do this. Resource dictionaries are all about sharing instances – they let you use a single instance of something (e.g. a style, a template, a brush, or whatever) from multiple places. They’re not really a mechanism for dividing your UI up to simplify individual Xaml files.

    The usual mechanism for splitting overly complicated Xaml files up into a few, more manageable smaller files is the user control. (Resource dictionary merging comes into play when you already have a resource dictionary, and it’s got too big. But you wouldn’t normally introduce a resource dictionary just to start splitting things up. On the contrary, resource dictionaries tend to encourage overly large Xaml files, which is why dictionary merging had to be invented in the first place!)

    Most of the time, when I define a data template, I make it contain nothing but a single user control. And if that becomes more complex, I’d split that user control up into more user controls.

    From your description, it sounds like your Xaml file has become large because you’ve got four large hierarchical data templates in there. If you took the body of each template and turned it into a user control, your four templates would now become very simple – something like this:

    <HierarchicalDataTemplate x:Key="t1" ItemsSource="{Binding Path=Children}">
        <loc:TreeItemTypeOne />
    </HierarchicalDataTemplate>
    

    and you’d most likely no longer need to put those templates into separate files. But because the guts of each template is now in a user control, that gives you a place to put your codebehind.

    You mention needing a reference to the parent control. That worries me – it makes it sound like you have too much code in your codebehind. But one thing at a time… You could solve that problem by defining a dependency property called ParentControl on your user control, and then put this in the template:

    <loc:TreeItemTypeOne
        ParentControl="{Binding RelativeSource=
            {RelativeSource AncestorType=loc:ParentControlType}}" />
    

    But frankly, as soon as I find myself in a position where I need this, I ask myself: how did I get myself into a position where that seemed necessary, and what can I do to fix that?

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

Sidebar

Related Questions

Is there a way I can pass parameters to the searchStyle function from the
Is there a way to pass dynamic parameters into a custom jquery validate method?
Is there a way to pass null arguments to C# methods (something like null
Is there a way to pass a call back function in a Java method?
Is there a way to pass a start time via URL when opening a
Does anybody know if there is a way using java to pass all the
How do you pass options to an executable? Is there an easier way than
Is there way in next piece of code to only get the first record?
is there way thats i can preselect an item when the page loads or
Is there a way to find the name of the program that is running

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.