RadTabItem Header Two Way binding not working

3 posts, 1 answers
  1. Omar
    Omar avatar
    16 posts
    Member since:
    Jul 2013

    Posted 26 Jan Link to this post

    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. Answer
    Martin
    Admin
    Martin avatar
    1101 posts

    Posted 28 Jan Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Omar
    Omar avatar
    16 posts
    Member since:
    Jul 2013

    Posted 30 Jan Link to this post

    Thank you Martin, you are right
Back to Top