Quick Access Toolbar controls and commands?

Ribbon for WPF Forum

Posted 11 years ago by Brad Daszynski
Version: 3.5.0421
Avatar
I want to confirm something: in order for cloned controls to work in the quick access toolbar the same way they do in the ribbon, they must be associated with or assigned a Command. For example, I have some button in my ribbon that, when cloned to the QAT, no longer do anything because I simply have event handlers attached to them. Am I correct? Thanks.

Comments (7)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
That is correct, it doesn't copy event handlers. However you can handle the CloneService.CloneCreatedEvent and tie them up again. More info on CloneService is in the documentation topic "Customizing the QAT".

Alternatively if you have any code snippets on cloning event hander ties, send them over and perhaps we can add that too.


Actipro Software Support

Posted 9 years ago by jon
Avatar
Hello,
as described, items added to the QAT are cloned and you have to refresh event handlers in CloneService.CloneCreatedEvent.
But how is that done?
In your installed examples there is only an empty OnCloneCreatedEvent event handler.

My problem: A <ribbon:Button> defined in XAML (under Ribbon.ApplicationMenu) has a property with a binding (defined in XAML). But if I add the button to the QAT (at runtime) the PropertyChanged event is not handled anymore by the clone. How can i fix this?

Actually, I think my problem is very common and I am wondering why you do not make sure that a clone acts exactly the same way as the source? I there a special reason doing so?

Thank you!

[Modified at 08/11/2010 04:45 AM]
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jon,

Cloning an object tree is a rather difficult thing. If you want to email us a simple sample project that shows an issue, we can look to see if we can improve the cloning for your scenario.


Actipro Software Support

Posted 9 years ago by jon
Avatar
Hello,
I have prepared a very trimmed-down example with only one button in the application menu:
The button's label property has a data binding to "Button1Text" property. If you click on the button, the property "Button1Text" is changed and the event "PropertyChanged" is fired. Now in the menu you can see, the button has a new label.
But if you add the button the the Quick Access Tool Bar (QAT) at runtime, further clicks on the button in the application menu do NOT UPDATE the button's label in the QAT (only in the menu)!!! (Clicks on QAT button do not work either.)

Could you please show me how to implement CloneService.CloneCreatedEvent, so that the QAT-Button does exactly the same as the original button?

Is there a common/universal implementation for CloneCreatedEvent? I do not want to handle every button individually, if I have button's with different property bindings / event handler / ...

Many thanks!

MainWindow.xaml:

<ribbon:RibbonWindow 
    x:Class="RibbonExample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:ribbon="clr-namespace:ActiproSoftware.Windows.Controls.Ribbon;assembly=ActiproSoftware.Ribbon.Wpf351" xmlns:Controls="clr-namespace:ActiproSoftware.Windows.Controls.Ribbon.Controls;assembly=ActiproSoftware.Ribbon.Wpf351" Title="MainWindow" Height="350" Width="525">
    <ribbon:Ribbon Name="myRibbon">
        <ribbon:Ribbon.ApplicationMenu>
            <Controls:ApplicationMenu>
                <Controls:Button Id="Button1" Label="{Binding Button1Text}" Click="Button_Click">
                </Controls:Button>
            </Controls:ApplicationMenu>
        </ribbon:Ribbon.ApplicationMenu>
        <ribbon:Ribbon.QuickAccessToolBarItems>
        </ribbon:Ribbon.QuickAccessToolBarItems>
    </ribbon:Ribbon>
</ribbon:RibbonWindow>
MainWindow.xaml.cs:

using System.ComponentModel;

namespace RibbonExample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
            Button1Text = "Button1";
            myRibbon.DataContext = this;
        }

        public string Button1Text { get; set; }

        private void Button_Click(object sender, ActiproSoftware.Windows.Controls.Ribbon.Controls.ExecuteRoutedEventArgs e)
        {
            Button1Text = Button1Text + "*";
            PropertyChanged(this, new PropertyChangedEventArgs("Button1Text"));
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jon,

Thanks for the sample. We've enhanced the clone service for the next version to duplicate property bindings on dependency properties. That fixes the Label binding.

However events are a different story. We're not aware of a way to easily duplicate those. If you know of any ways, please do share. So for those, you'd have to do things like this where I gave your ribbon:Button a Name and added this code:
static MainWindow() {
    EventManager.RegisterClassHandler(typeof(MainWindow), CloneService.CloneCreatedEvent, new EventHandler<DependencyObjectItemRoutedEventArgs>(OnCloneCreated));
}

private static void OnCloneCreated(object source, DependencyObjectItemRoutedEventArgs e) {
    MainWindow window = (MainWindow)source;
    FrameworkElement element = e.OriginalSource as FrameworkElement;
    if (element != null) {
        switch (element.Name) {
            case "Button1": {
                RibbonControls.Button button = (RibbonControls.Button)e.Item;
                button.Click += window.Button_Click;
                break;
            }
        }
    }
}
If you use commands instead of events, you could eliminate the need for this step.


Actipro Software Support

Posted 9 years ago by jon
Avatar
Hi,
Many thanks for your reply.
I think I cannot wait for the next version that duplicates property bindings. Maybe you know how to duplicate property bindings so that label binding in my example works? Perhaps you could post it?

(By the way: If you clone dependency property bindings in an new version, and someone updates the new version, then he suddenly has buttons in QAT that work. But perhaps he does not want that?!)
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jon,

We've emailed you our code snippet. The next version will be a major version 2010.2 and we'll mark this as a potential breaking change.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.