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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:40:27+00:00 2026-05-21T09:40:27+00:00

According to msdn , it should be perfectly legal, and possible, to bind something

  • 0

According to msdn, it should be perfectly legal, and possible, to bind something to a nested property:

<Binding Path="propertyName.propertyName2" .../>
<Binding Path="propertyName.propertyName2.propertyName3" .../>

In my case, it’s not so, though…

I have a custom control, MyControl, with a dependency property ViewModel:

    public static DependencyProperty ViewModelProperty = DependencyProperty.Register(
        "ViewModel", typeof(IViewModel), typeof(MyControl));

    public IViewModel ViewModel
    {
        get { return (IViewModel)GetValue(ViewModelProperty); }
        set { SetValue(ViewModelProperty, value); }
    }

and in the control template, I try to bind to properties in that viewmodel:

 <Style TargetType="{x:Type my:MyControl}">
   <Setter Property="Template">
     <Setter.Value>
       <ControlTemplate TargetType="{x:Type my:MyControl}">
         <Grid>
           <TextBox Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Text}"/>
           <Button x:Name="MyButton" Content="Visible by trigger" Visibility="Collapsed" />
         </Grid>
       <ControlTemplate.Triggers>
         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.ButtonVisible}" Value="True">
           <Setter TargetName="MyButton" Property="Visibility" Value="Visible" />
         </DataTrigger>            
      .../>

In the viewmodel itself, I have a preoperty Text as follow:

    public string Text
    {
        get { return m_text; }
        set
        {
            m_text = value;
            OnPropertyChanged("Text");
        }
    }

    public bool ButtonVisible
    {
      get { return m_buttonVisible; }
      set 
     { 
       m_buttonVisible = value; 
       OnPropertyChanged("ButtonVisible"); }
     }

I get no bind errors, but things doesn’t happend…

Any clues?

Edit
It looks like the bindings work half way. When the text is changed in the editbox, my Text property is set, but if the Text-property is set in code, the ui won’t update.

Edit 2
Looks like my first attempt at simplifying the case before posting was a little to successful… As @Erno points out, the code that I posted seems to work OK.

I have looked at the original code some more, and added a trigger to the scenario. The original code uses triggers to show parts of the ui at given conditions. These are also binded to nested properties. I now think that these triggers fail to trigger. I have updated the code. If it still doesn’t show whats wrong, I can post a sample application some where.

  • 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-21T09:40:28+00:00Added an answer on May 21, 2026 at 9:40 am

    There is a comma missing:

    <TextBox Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Text}"/>
    

    EDIT

    Add Mode=TwoWay to the binding:

    <TextBox Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Text, Mode=TwoWay}"/>
    

    EDIT2

    Got it! I could reproduce and fix it.

    Replace the TemplatedParent with Self in the binding.
    Read this explanation

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

Sidebar

Related Questions

According to the MSDN documentation for the WindowStartupLocation Property : Setting CenterScreen causes a
According to MSDN in .Net DateTimeFormat.MonthName should contain exactly 13 elements with 12 element
According to msdn it should be in windbase.h but it is not available instead
According to MSDN on DateTime.ToString ToString(s) should always return string in the format of
According the the MSDN documentation, the following code should output '5' to the console
According to MSDN , Silverlight static resources lookup mechanism should: The lookup behavior for
According to http://msdn.microsoft.com/en-us/library/ms535934(v=VS.85).aspx and http://msdn.microsoft.com/en-us/library/ms535262(v=VS.85).aspx , I should be able to do the following
According to [MSDN: Array usage guidelines]( http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx) : Array Valued Properties You should use
According to this MSDN article , you should not catch general exceptions. I'm sure
According MSDN, FxCop is an application that analyzes managed code assemblies (code that targets

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.