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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:06:21+00:00 2026-06-12T05:06:21+00:00

A little bit can’t figure out how to use WPF binding in this case:

  • 0

A little bit can’t figure out how to use WPF binding in this case:

Assume, we have an object Car with non-simple property of type CarInfo:

public class CarInfo : DependencyObject
{
    public static readonly DependencyProperty MaxSpeedProperty =
        DependencyProperty.Register("MaxSpeed", typeof (double), typeof (CarInfo), new PropertyMetadata(0.0));

    public double MaxSpeed
    {
        get { return (double) GetValue(MaxSpeedProperty); }
        set { SetValue(MaxSpeedProperty, value); }
    }
}

public class Car : DependencyObject
{

    public static readonly DependencyProperty InfoProperty =
        DependencyProperty.Register("Info", typeof (CarInfo), typeof (Car), new PropertyMetadata(null));

    public CarInfo Info
    {
        get { return (CarInfo) GetValue(InfoProperty); }
        set { SetValue(InfoProperty, value); }
    }

}

Also assume, Car is an ui element and it has the Car.xaml, something simple:

<Style TargetType="assembly:Car">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="assembly:Car">
                <Grid >
    !-->            <TextBlock Text="{Binding Path=MaxSpeed}" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

So, I wanted this TextBlock, in my Car.xaml, to represent the property “MaxSpeed” of my CarInfo class, which is actually a property of my Car class. How can I do this?

Thank you in advance, appreciate any help! 🙂

  • 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-06-12T05:06:22+00:00Added an answer on June 12, 2026 at 5:06 am

    It depends upon what is assigned to the DataCOntext of the UI element representing the Car – you need to specify a binding path relative to that. In this case I would suggest you start with this:

    <TextBlock Text="{Binding Path=Info.MaxSpeed}" />
    

    this is assuming that a Car object has been assigned to the DataContext of the Car UI element.

    Note that your properties don’t have to be dependency properties – you can also bind to normal properties (depending on what you are doing).

    Edit

    It seems you are looking to use element binding, so you should be able to achieve what you want by using either the TemplatedParent or an ancestor as your relative source. See this previous SO answer for an example. Your binding should look something like this:

    <TextBlock Text="{Binding Path=Info.MaxSpeed, RelativeSource={RelativeSource TemplatedParent}}" />
    

    This will take you back to your templated parent control (the Car), then travel down the Info property of the UI element to the MaxSpeed property on its contents.

    As I said in my comment, you are making this very messy by having your UI element so closely match your data element and then assigning your data object to a relatively non standard property on the UI element. You might have your reasons, but XAML and WPF don’t need to be that complicated.

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

Sidebar

Related Questions

I'm a little bit new to Actionscript, but I can't figure this one out.
I have a little bit complex MySQL query for me and i can't figure
I'm a little bit confused, how to do this. I know I can use
I have this annoying little bit of spacing I can't remove. Here's a fiddle.
I have this little bit of code that I can't quite work correctly. The
I'm getting a little bit frustrated since I can't find out which variables I
I have little bit knowledge on Entity Framework.As we can do almost all operations
This is a lovely little bit of SQL which I can't write. :) what
I've been tinkering with this a little bit as well and can't quite understand
It took me a little bit, but I figured out that I can't click

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.