This is a migrated thread and some comments may be shown as answers.

RadTabItem Header Two Way binding not working

2 Answers 35 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Omar
Top achievements
Rank 1
Omar asked on 26 Jan 2016, 08:40 PM

I have applied an editable radtabitem header as the following

 I can see the editable TextBox set the the initial value for the header I can change it , but the Header Property it self still the same , so please what is wrong here?

 

<Style TargetType="{x:Type socialtracker:EditableTabHeaderControl}">
               <Setter Property="Template">
                   <Setter.Value>
                       <ControlTemplate TargetType="{x:Type socialtracker:EditableTabHeaderControl}">
                           <Grid>
                               <Grid.Triggers>
                                   <EventTrigger RoutedEvent="Grid.DragEnter">
                                       <BeginStoryboard x:Name="GridBeginStoryboard">
                                           <Storyboard>
                                               <DoubleAnimation Storyboard.TargetName="ButtonTransform" Storyboard.TargetProperty="ScaleX" Duration="0:0:0.5" From="1" To="1.1"/>
                                               <DoubleAnimation Storyboard.TargetName="ButtonTransform" Storyboard.TargetProperty="ScaleY" Duration="0:0:0.5" From="1" To="1.1"/>
                                           </Storyboard>
                                       </BeginStoryboard>
                                   </EventTrigger>
                                   <EventTrigger RoutedEvent="Grid.DragLeave">
                                       <StopStoryboard BeginStoryboardName="GridBeginStoryboard"/>
                                   </EventTrigger>
                                   <EventTrigger RoutedEvent="Grid.Drop">
                                       <StopStoryboard BeginStoryboardName="GridBeginStoryboard"/>
                                   </EventTrigger>
                               </Grid.Triggers>
                               <TextBox x:Name="PART_EditArea"
                           Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content, Mode=TwoWay}"
                           Visibility="Collapsed" />
                               <ContentPresenter x:Name="ContentPresenter"
                           Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content, Mode=TwoWay}" />
                           </Grid>
                           <ControlTemplate.Triggers>
                               <Trigger Property="IsInEditMode" Value="True">
                                   <Trigger.Setters>
                                       <Setter TargetName="PART_EditArea" Property="Visibility" Value="Visible" />
                                       <Setter TargetName="ContentPresenter" Property="Visibility" Value="Collapsed" />
                                   </Trigger.Setters>
                               </Trigger>
                           </ControlTemplate.Triggers>
                       </ControlTemplate>
                   </Setter.Value>
               </Setter>
           </Style>

Binding binding = new Binding
                   {
                       Path = new PropertyPath("."),
                       Mode = BindingMode.TwoWay,
                   };
 
                   var editableTabHeaderControl = new FrameworkElementFactory(typeof(EditableTabHeaderControl));
                   editableTabHeaderControl.SetBinding(EditableTabHeaderControl.ContentProperty, binding);
                   DataTemplate newDataTemplate = new DataTemplate() { VisualTree = editableTabHeaderControl, };                   
                    
                   RadTabItem item = new RadTabItem
                   {
                       Tag = new ObservableCollection<Tweet>(),
                       Name = "SelectedPrint" + _intSelectedPrintTabsCount.ToString(),
                       Header = " New Tab " + _intSelectedPrintTabsCount.ToString(),
                       HeaderTemplate =  newDataTemplate 
                                             
                   };
                    
                   tbSearchAndFOllow.Items.Insert(tbSearchAndFOllow.Items.Count - 1, (item));

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 28 Jan 2016, 10:15 AM
Hi Omar,

The binding doesn't work as expected because the WPF framework doesn't support TwoWay binding directly to the source object. In order to achieve your requirement, you can set the tab item as a Source of the binding and then set the Path to point to the Header property. Here is an example:
RadTabItem item = new RadTabItem
{
    Tag = new ObservableCollection<Object>(),
    Name = "SelectedPrint" + _intSelectedPrintTabsCount.ToString(),
    Header = " New Tab " + _intSelectedPrintTabsCount.ToString(),
};
 
Binding binding = new Binding
{
    Source = item,
    Path = new PropertyPath("Header"),
    Mode = BindingMode.TwoWay,
};
 
var editableTabHeaderControl = new FrameworkElementFactory(typeof(EditableTabHeaderControl));
editableTabHeaderControl.SetBinding(EditableTabHeaderControl.ContentProperty, binding);
DataTemplate newDataTemplate = new DataTemplate() { VisualTree = editableTabHeaderControl, };
 
item.HeaderTemplate = newDataTemplate;
 
tbSearchAndFOllow.Items.Insert(tbSearchAndFOllow.Items.Count - 1, (item));

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Omar
Top achievements
Rank 1
answered on 31 Jan 2016, 05:02 AM
Thank you Martin, you are right
Tags
TabControl
Asked by
Omar
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Omar
Top achievements
Rank 1
Share this question
or