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

Can Breadcrumb items be bound to commands?

1 Answer 80 Views
BreadCrumb
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 31 Mar 2018, 12:09 AM

Hi, I have not been able to find documentation yet on how to handle events generated by the RadBreadcrumb control, can you point me at the docs?  I would really like to bind inidividual 'crumbs' to an ICommand using MVVM. (the same way I would bind a button's Command property to an ICommand)  If that's not possible, is there anything else I can do to bind to this control, or do I have to use the events?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 03 Apr 2018, 12:45 PM
Hello Joshua,

When you need to bind events to command in your viewmodel following the MVVM pattern, you can use the EventToCommandBehavior helper class. Here's how you can set it up in this case:

<telerik:RadBreadcrumb>
    <telerik:EventToCommandBehavior.EventBindings>
        <telerik:EventBinding EventName="MouseLeftButtonDown" Command="{Binding ClickCommand}" PassEventArgsToCommand="True" RaiseOnHandledEvents="True" />
    </telerik:EventToCommandBehavior.EventBindings>
    <!-- ... -->
</telerik:RadBreadcrumb>

Note that the MouseLeftButtonDown event is handled internally, you need to set the RaiseOnHandledEvents property of the EventBinding to True.

In addition, you will probably require the event arguments in your command's logic. This is where the PassEventArgsToCommand property comes in handy.

Here's how you can get the item that has been clicked:

public class MainWindowViewModel : ViewModelBase
{
    public ICommand ClickCommand { get; set; }
 
    public MainWindowViewModel()
    {
        this.ClickCommand = new DelegateCommand(OnClick);
    }
 
    private void OnClick(object obj)
    {
        var args = obj as MouseButtonEventArgs;
        var source = args.OriginalSource as FrameworkElement;
        var item = source.ParentOfType<RadBreadcrumbBarItem>();
        if (item != null)
        {
            Debug.WriteLine(item.Header);
        }
    }
}

For your convenience, I'm also attaching a sample project with the implementation.

I hope you find all of this helpful. Should any further questions or concerns arise, please let me know.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
BreadCrumb
Asked by
Joshua
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or