Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > RibbonBar > Bindig to "Header" or "Text" Properties

Not answered Bindig to "Header" or "Text" Properties

Feed from this thread
  • Sebastian avatar

    Posted on Jan 19, 2012 (permalink)

    Hello there,

    i have a problem:

    I am binding all itmes in my RadRibbonBar (few tabs with groups and buttons on them), e.g. the Header Property of a RadRibbonTab to a String from a resx-file - this is done via a class which returns a settings/language/whatever specific object. The initial display of the string is absolutely correct.

    XAML Looks like:

    <telerik:RadRibbonTab Header="{Binding Path=myMenus.RibbonFormular, Source={StaticResource my_Strings }}" x:Name="RibbonFormular" [...] >

    How can i programmatically refresh such a binding?

    If i iterate through the controls on the page, i try something like the below, but besides some isselected property no binding seems to exist at all.

                foreach (var control in controls)
                {
                            foreach (var f in control.GetType().GetFields())
                            {
                                DependencyProperty dp = f.GetValue(control) as DependencyProperty;
                                if (dp != null)
                                {
                                    BindingExpression be = ((FrameworkElement)control).GetBindingExpression(dp);
                                    if (be != null && be.ParentBinding.Source != null && be.ParentBinding.Path != null)
                                    {
                                        Binding bind = be.ParentBinding;
                                        ((FrameworkElement)control).SetBinding(dp, bind);
                                    }
                                }
                            }
                        }               
                }
      
    As an alternative, a way to iterate through all controls and set the header/text property as a simple string would be (although less preferred) way i could do that - unfortunately a recursive search for all dependency objects never return all object i expect the radribbonbar to have, e.g. does it not find unselected tabs as it seems.

    Any suggestions are welcome,
    thanks in advance.

    Reply

  • Tina Stancheva Tina Stancheva admin's avatar

    Posted on Jan 20, 2012 (permalink)

    Hi Sebastian,

    I will post the same information I gave you in the support ticket in case anyone else encounters such an issue:

    In your case it would be better to take advantage of the new RadRibbonView control. It has the same API as the RibbonBar control but it further enhances the 'ribbon UI' databinding capabilities and its functionality (read more). Also the structure of the RibbonView elements is improved to facilitate the efforts when interacting with the ribbon content elements.

    So when using RadRibbonView control you can implement such a custom logic on a button click:
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        foreach (RadRibbonTab tab in radRibbonView.Items)
        {
            BindingExpression be = tab.GetBindingExpression(RadRibbonTab.HeaderProperty);
            if (be != null && be.ParentBinding.Source != null && be.ParentBinding.Path != null)
            {
                (be.ParentBinding.Source as Strings).Tab1Header = "New Tab1 Header";
                (be.ParentBinding.Source as Strings).Tab2Header = "New Tab2 Header";
                (be.ParentBinding.Source as Strings).Tab3Header = "New Tab3 Header";
     
                Binding bind = be.ParentBinding;
                tab.SetBinding(RadRibbonTab.HeaderProperty, bind);
            }
        }
    }
    The foreach operator will iterate through all RadRibbonTabs and get the binding applied on their header so that you can update it as required.

    Greetings,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > RibbonBar > Bindig to "Header" or "Text" Properties