Disabling RadRichTextBoxRibbonUI when focus is not on a RichTextBox

6 posts, 0 answers
  1. papadi
    papadi avatar
    35 posts
    Member since:
    Nov 2008

    Posted 27 Sep 2012 Link to this post

    Hi!
    I have several controls on my form, among which some RichTextBox instances. The for has RadRichTextBoxRibbonUI on top. When a RichTextBox  gets the focus (GotFocus event) I'm binding the DataContext of the ribbon with its Commands property. When focus is lost (LostFocus) I want to disable this binding and disable all the buttons of the ribbon that are bound to the richtextbox commands (all the buttons of the ribbon that have the RadRichTextBoxRibbonUI.RichTextCommand attribute).
    How can I do that? Setting the DataContext of the ribbon to null does not disable it.
  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    104 posts

    Posted 01 Oct 2012 Link to this post

    Hello papadi,

    By default the button controls are enabled even when they don't have a binding. That's why removing the data context command property does not affect their state to disabled. Our suggestion is to traverse through all the buttons in the ribbon and manually set their state.

    If you find difficulties in implementing such behavior, write back to us.

    Greetings,
    Martin
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  3. UI for WPF is Visual Studio 2017 Ready
  4. papadi
    papadi avatar
    35 posts
    Member since:
    Nov 2008

    Posted 01 Oct 2012 Link to this post

    Can you help me with that? Should I use the Items property of the ribbon or there is an easier way to get the collection of buttons in the ribbon?
  5. Martin Ivanov
    Admin
    Martin Ivanov avatar
    104 posts

    Posted 04 Oct 2012 Link to this post

    Hello Dimitrios,

    You can use the IsEnabled property of the ribbon elements to disable them. In order to determine which buttons should be enabled and disabled, you can give them names in XAML.

    You can also use the ChildrenOfType<T> extension method from the Telerik.Windows.Controls assembly.
    First you need to add:

    using Telerik.Windows.Controls;

    Then you can use it to disable all controls of a certain type like this:
    foreach (var item in this.radRichTextBoxRibbonUI1.ChildrenOfType<RadRibbonComboBox>())
    {
        item.IsEnabled = false;
    }

    I hope this helps.

    All the best,
    Martin
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. papadi
    papadi avatar
    35 posts
    Member since:
    Nov 2008

    Posted 27 May 2013 Link to this post

    I'm coming back after quite a while with this. Back then I did use the ChildrenOfType method to get the items of the ribbon. The problem now is that I discovered that this function returns only the items of the currently visible tab and not all of the items of the Ribbon!
    Any ideas?
  7. Boby
    Admin
    Boby avatar
    595 posts

    Posted 30 May 2013 Link to this post

    Hi Papadi,
    Maybe better solution would be to enable/disable all needed groups in the ribbon - for example by binding their IsEnabled property to your custom converter, which computes when RadRichTextBox has focus.

    Another option is to give names to all the groups, and in case of losing/receiving focus manually set the IsEnabled properties of the groups.

    You can also set IsEnabled property of the tabs itself, but this would make them unselectable.

    Regards,
    Boby
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready