0

For my example let's say I have this in my DataContext :

    public object SomeProperty 
    {  
        get;
        set{ .... 
               PropertyChanged(....);  
           }
    }

XAML :

   <ContentControl Tag="{Binding SomeProperty}" x:Name="myContentControl" />

Now in my DataContext I need to reference myContentControl.

Is there any way through the Binding object created to resolve the binding Target (ContentControl.TagProperty) through the Binding Source (MyViewModel.SomeProperty)?

Question Context :

I have a CustomControl Deriving from DataGrid , this grid supports Filtering throw the header , inside the header template i placed a TextBox . The grid itself listens to TextChanged event and filters each column by that text .

Instead of saving a reference to each TextBox , or alternatively traversing the VisualTree I was wondering if i could track the TextBox from the reference i saved to textBox.Text.

 var filterValue = textBox.Text;
 values.Add(source,filterValue); // Dictionary 

tow questions come to mind :

1) Because Text is a string and there for immutable i'm not sure how binding keeps track of it .

2) Is it possible to resolve the Binding Target from the Binding Source (Path) ?

eran otzap
  • 12,293
  • 20
  • 84
  • 139
  • That's not how it is supposed to be used. Why do you need to access `myContentControl` in your view model? – Daniel Hilgarth Sep 02 '13 at 16:23
  • I don't it was an arbitrary example of what i need , so i won't get asked questions that begin with "Why" , I failed :( – eran otzap Sep 02 '13 at 16:25
  • @DanielHilgarth I have a Control Deriving From DataGrid , in each ColumnHeader a have a TextBox , which i wan't to resolve through the TextProperty i saved a reference to , Now this raises the question does binding update it's source for emutable objects.. ( So i didn't want to get into that yet ). – eran otzap Sep 02 '13 at 16:27
  • If that's not what you want to actually do, maybe update your question to show what you really want to do. There is no point in answering this question if that's not what you want to do. – Daniel Hilgarth Sep 02 '13 at 16:27
  • @DanielHilgarth I disagree , I'm asking a clearly Theoretical question , in order to grasp a bigger picture of what can and can't be done , my implementation and objectives should be of no interest to the good people here . – eran otzap Sep 02 '13 at 16:30
  • Very often, people ask one question when they actually should ask another question (see [XY problem](http://mywiki.wooledge.org/XyProblem)). To identify such questions and safe everybody a lot of time, the context is relevant. – Daniel Hilgarth Sep 02 '13 at 16:35
  • @DanielHilgarth i edited the question . 10x. – eran otzap Sep 02 '13 at 16:59
  • Create a proper ViewModel for your Grid. That will save you from having to do a lot of winforms-like horrible hacks. – Federico Berasategui Sep 02 '13 at 17:57

0 Answers0