Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a collection that is posted into a TabControl (rather a custom TabControl 3rd Party) and I want to use the "AccessText" of the TabItem header. I am having troubles accessing it though... For example (I know this is wrong) I want to do this

XML
<Style TargetType="TabItem.Header.AccessText">
            <Setter Property="Text" Value="{Binding Path=DisplayName}"/>
        </Style>



Note that DisplayName will have something like _Customers meaning the accessor will work if they press 'C'.
Also it does not have to be a style, but that was the simpliest way to get the point across (IMO)
Thank you in advance.
Posted
Updated 28-Apr-11 8:56am
v2

Remember, styles are independent entries which can be applied to more than one object to get the same look and feel for both. You should not be using Binding to get some external data into styles.


Rather use ControlTemplate to apply it to child elements or even apply it directly using DataContext.

< ... AccessText="{Binding RelativeSource={RelativeSource .... DisplayName ... }}"


Something like this or directly AccessText="{Binding DisplayName}"

Making Binding Mode=TwoWay means the data will be updated in Both direction.
 
Share this answer
 
Comments
Nish Nishant 28-Apr-11 15:42pm    
Good answer, AS. My vote of 5.
[no name] 28-Apr-11 18:09pm    
Isn't that why they can have keys?
I had already tried using a DataTemplate but it changed the behavior because I had to place an item there.
For example, placing a TabItem inside can get the behavior... but broken. Inside each tabitem is another tabitem with its focus set. I.E. the hot key will not work.
With out using the AccessText of the TabItem Header the same effect can be acheived.

XML
<Style x:Key="BindingTabItems" TargetType="TabItem">
        <Setter Property="Header" Value="{Binding Path=DisplayName}"/>
    </Style>


And of course the key is added so that not all TabItems have the behavior...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900