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

  • Home
  • SEARCH
  • 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 4022684
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:30:23+00:00 2026-05-20T10:30:23+00:00

In a WPF Custom Control template, is there any way that I can do

  • 0

In a WPF Custom Control template, is there any way that I can do the following in XAML?:

var selItemText = this.GetTemplateChild("PART_SelectedItemText") as TextBlock;
var binding = new Binding("SelectedItem." + DisplayMemberPath);
binding.RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent);
selItemText .SetBinding(TextBlock.TextProperty, binding);

Note that the interesting part of this statement is the binding constructor – I am building up a path based on both some text I specify (“SelectedItem.”), and the path provided by the user.

The consumer would use the control similar to:

<c:MyControl DisplayMemberPath="Description" />
  • 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-20T10:30:24+00:00Added an answer on May 20, 2026 at 10:30 am

    short answer: no, it’s not possible to get this entirely in xaml within the controltemplate

    your possibilities are:

    • use what you have (possibly using attached properties / a behavior to make it more MVVM-like)
    • use a MultiBinding one binding to the “SelectedItem” the other to “DisplayMemberPath” and your MultiValueConverter using Reflection to reflect down the DisplayMemberPath (may be a bit ugly)
    • create a class that inherits from Binding and exposes Properties that you can bind the DisplayMemberPath to and changes the underlying Binding (read here for how you can do this) (complicated)
    • use Reflection to instantiate a MS.Internal.Data.DisplayMemberTemplateSelector / build something similar
    • think about if your design is right. Other than your Control being some kind of ItemsControl (if that was the case you should inherit from ItemsControl and use the DisplayMemberPath you get there), I don’t see why you shouldn’t use a Binding on the outside like <c:MyControl DisplayMember="{Binding SelectedItem.Description}" /> and in your ControlTemplate use a TemplateBinding to bind to “DisplayMember”
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom control in WPF that simply holds a combo box (however
There is a custom control called TestCustomControl, it inherits from Control and it has
When I create a custom control in WPF and add it to a window,
I am developing a custom WPF control and confused how to use the dependency
I'm trying to make a custom WPF control where a TranslateTransform is applied based
I have a WPF CustomControl that is derived from ComboBox and I'm trying to
I am creating paint like application using WPF. Now i need to create control
We are writing a WPF based application that is usually used on a touchscreen
I have been struggling with this for a while now. I have a Master
I would like to make a library of some of my commonly used WPF

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.