More PanelBar commanding

4 posts, 0 answers
  1. Mark Westwood
    Mark Westwood avatar
    3 posts
    Member since:
    Dec 2009

    Posted 03 Feb 2010 Link to this post

    Hi, Im using Prism + Wpf and trying to get the commanding to work on a button i have placed in the panel bar using a datatemplete. Here is a copy of the datatemplate:

    <DataTemplate x:Key="RadPanelBarItemTemplate">
                    <StackPanel Orientation="Vertical" Margin="1" HorizontalAlignment="Left">
                        <Button Width="140" Height="25" Margin="2"
                                Tag="{Binding Tag}"
                                Content="{Binding Title}"
                                ToolTip="{Binding Description}"
                                commands:Click.Command="{Binding NavigationBarClickCommand}"
                                commands:Click.CommandParameter="{Binding Tag}"/>
                    </StackPanel>
                </DataTemplate>

    Is this possible, at the moment my command is never getting fired. Or should I be using a different approach?

    Thanks, Mark


  2. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 04 Feb 2010 Link to this post

    Hello Mark,

    The code snippet you provided should work without problems. Are you sure the command you are binding to is part of the DataContext of the DataTemplate (it should be a property of the business object that will be rendered via the DataTemplate)?

    Kind regards,
    Tihomir Petkov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mark Westwood
    Mark Westwood avatar
    3 posts
    Member since:
    Dec 2009

    Posted 04 Feb 2010 Link to this post

    Hi,

    Thanks for the response. I'm not sure I fully understand but I have my Command setup as public within my ViewModel as:

    public NavigationBarViewModel(IUnityContainer container, IRegionManager regionManager, IEventAggregator eventAggregator)//, IConnectionBarController controller)
            {

    I',m not sure what you mean by making it a property of the DataTemplate. Obviously my ViewModel is the BindingSource of the View.

    Mark
                log.Info("ConnectionVarViewModel");

                this.container = container;
                this.regionManager = regionManager;
                this.eventAggregator = eventAggregator;
                //Controller = controller;
                
                NavigationBarClickCommand = new DelegateCommand<string>(OnButtonClick);//, CanButtonClick);
  5. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 04 Feb 2010 Link to this post

    Hi Mark,

    The problem is that the DataContext of your DataTemplate (where you try to bind to the command) is different than the DataContext of your View (where the command is defined). In the DataTemplate you can only bind to properties of the business object that will be rendered via that template.

    A possible solution is to make the command in the ViewModel static and add a property to your business objects that returns the command.

    Let me know if the suggested approach will work for you.

    Best wishes,
    Tihomir Petkov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
Back to Top