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 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 there any chance in WPF to do a event for control in template
I am trying to create a custom wpf control, I'm wondering how I can
In WPF, I have a custom control that inherits from TreeView. The code is
I'm inserting a custom winform control in a WPF/ XAML window, however i'm realising
Is there a custom UserControl created in WPF that allows for RDP access. I
I am creating a custom WPF control that let's say for simplicity sake has
We can make WPF Custom Control for overriding some control's look&feel, like icon button.
I'm trying to create a custom control that can be shared by both Silverlight
I'm writing a generic control template for my WPF Custom Control. But with ItemsPresenter
I need to write a custom WPF control that should look like a ComboBox

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.