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

More PanelBar commanding

3 Answers 36 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Mark Westwood
Top achievements
Rank 1
Mark Westwood asked on 04 Feb 2010, 05:09 AM
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


3 Answers, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 04 Feb 2010, 08:48 AM
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.
0
Mark Westwood
Top achievements
Rank 1
answered on 04 Feb 2010, 11:16 AM
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);
0
Tihomir Petkov
Telerik team
answered on 04 Feb 2010, 03:45 PM
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.
Tags
PanelBar
Asked by
Mark Westwood
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Mark Westwood
Top achievements
Rank 1
Share this question
or