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

Binding Button to RadGridCommand

4 Answers 117 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 2
David asked on 07 Sep 2012, 01:04 PM
Hi,

I have been looking at the Command example in the wpf examples and I'm trying to bind a button click to a Grid Command

I have a RibbonBar and on the RibbonBar I have some navigation buttons (First,Last,Next,Previous)

I then have a RadTabControl with a few tab pages on I have a ContentTemplateSelector which depending on a value will add a RadGridView with set columns to the tab page.

it is this GridView i'm trying to add the bindings too.

Hope I have explained what i'm trying to do :)

thanks David

4 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 07 Sep 2012, 03:09 PM
Hi David,

 Can I ask you to describe with details what actually is your problem? It will be great if you can send us a sample project by opening a new support ticket.

Greetings,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
David
Top achievements
Rank 2
answered on 07 Sep 2012, 03:25 PM
Hi,

There isn't actually an issue, I'm just new to WPF and cant work out how I should Bind the button click in the RadRibbonMenu to the RadGridView from a DataTemplate.

The Idea is that the Window will open a file and depending on the file there will be 3 to 6 tabs in the Tab Control each tab will have a GridView on them. I want to be able to bind the buttons on the RadRibbonMenu to the GridView in the Selected Tab. 

Thanks

In my Window.xml I have

Window x:Class="WPFDataImport.MainWindow"
        xmlns:local="clr-namespace:WPFDataImport"
        xmlns:vm="clr-namespace:ViewModels;assembly=ViewModels"
        Title="MainWindow" Height="350" Width="525">
    <Window.DataContext>
        <!-- Declaratively create an instance of our SongViewModel -->
        <vm:MainWindowViewModel />
    </Window.DataContext>
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary
                  Source="FileTemplates.xaml">
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
             
            <DataTemplate x:Key="TabItemTemplate">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                    <TextBlock Text="{Binding Header}" />
                </StackPanel>
            </DataTemplate>
 
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
 
        <telerik:RadRibbonView x:Name="MainRibbonView"
                                ApplicationName="Activity Data Import"
                                Grid.Row="0"
                                MinimizeButtonVisibility="Visible"
                                HelpButtonVisibility="Visible" IsBackstageOpen="False">
 
            <telerik:RadRibbonView.ApplicationButtonContent>
                <TextBlock Text="File" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0 4 0 0" />
            </telerik:RadRibbonView.ApplicationButtonContent>
 
            <telerik:RadRibbonView.Backstage>
                <telerik:RadRibbonBackstage >
                </telerik:RadRibbonBackstage>
            </telerik:RadRibbonView.Backstage>
 
            <telerik:RadRibbonTab Header="Home" telerik:KeyTipService.AccessText="H">
                <telerik:RadRibbonGroup Header="Clipboard">
                    <telerik:RadRibbonSplitButton Text="Paste" SmallImage="{Binding Paste_16}"
                            LargeImage="{Binding Paste_32}" Size="Large" telerik:ScreenTip.Title="Paste"
                            telerik:ScreenTip.Description="Paste the contents of the Clipboard."
                            telerik:KeyTipService.AccessText="V">
                        <telerik:RadRibbonSplitButton.DropDownContent>
                            <telerik:RadMenu>
                                <telerik:RadMenuItem Header="Paste" telerik:KeyTipService.AccessText="S">
                                    <telerik:RadMenuItem.Icon>
                                        <Image Width="16" Height="16" Stretch="Fill" Source="{Binding Paste_16}" />
                                    </telerik:RadMenuItem.Icon>
                                </telerik:RadMenuItem>
                                <telerik:RadMenuItem Header="Paste Append" telerik:KeyTipService.AccessText="H">
                                    <telerik:RadMenuItem.Icon>
                                        <Image Stretch="None" Source="{Binding Pastespecia}" />
                                    </telerik:RadMenuItem.Icon>
                                </telerik:RadMenuItem>
                            </telerik:RadMenu>
                        </telerik:RadRibbonSplitButton.DropDownContent>
                    </telerik:RadRibbonSplitButton>
                    <StackPanel Orientation="Vertical">
                        <telerik:RadRibbonButton Text="Cut" SmallImage="{Binding Cut}"
                                CollapseToSmall="WhenGroupIsMedium" telerik:ScreenTip.Title="Cut"
                                telerik:ScreenTip.Description="Cut the selection from the document and put it on the Clipboard." />
                        <telerik:RadRibbonButton Text="Copy" SmallImage="{Binding Copy_16}"
                                CollapseToSmall="WhenGroupIsMedium" telerik:ScreenTip.Title="Copy"
                                telerik:ScreenTip.Description="Copy the selection and put it on the Clipboard." />
 
                    </StackPanel>
                </telerik:RadRibbonGroup>
 
                <telerik:RadRibbonGroup Header="Records">
                    <StackPanel Orientation="Vertical">
                        <StackPanel Height="40" Orientation="Horizontal">
                            <telerik:RadRibbonButton Name="First" Content="|<" Width="30" />
                            <telerik:RadRibbonButton Name="Previouse" Content="<" Width="30"/>
                            <telerik:RadRibbonButton Name="Next" Content=">" Width="30"/>
                            <telerik:RadRibbonButton Name="Last" Content=">|" Width="30" />
                        </StackPanel>
                        <TextBox Name="CurrentRecord" Text="{Binding SpellRecordCount,Mode=OneWay}"/>
                    </StackPanel>
                </telerik:RadRibbonGroup>
 
                <telerik:RadRibbonGroup Header="Data">
                    <telerik:RadRibbonButton Text="Save" SmallImage="{Binding Save_16}"
                            LargeImage="{Binding Save_32}" Size="Large" telerik:ScreenTip.Title="Save"
                            telerik:ScreenTip.Description="Save the data to a file."
                            telerik:KeyTipService.AccessText="S">
                    </telerik:RadRibbonButton>
                    <StackPanel Orientation="Vertical">
                        <telerik:RadRibbonButton Text="Add" SmallImage="{Binding Add}"
                                CollapseToSmall="WhenGroupIsMedium" telerik:ScreenTip.Title="Add"
                                telerik:ScreenTip.Description="Add a new data line."
                                telerik:KeyTipService.AccessText="A" />
                        <telerik:RadRibbonButton Text="Delete" SmallImage="{Binding Delete_16}"
                                CollapseToSmall="WhenGroupIsMedium" telerik:ScreenTip.Title="Delete"
                                telerik:ScreenTip.Description="Delete the selected data."
                                telerik:KeyTipService.AccessText="D" />
 
                    </StackPanel>
                </telerik:RadRibbonGroup>
 
            </telerik:RadRibbonTab>
        </telerik:RadRibbonView>
 
        <telerik:RadTabControl x:Name="tabControl" Grid.Row="1" ItemsSource="{Binding Tabs}" OverflowMode="Wrap" ItemTemplate="{StaticResource TabItemTemplate}" ContentTemplateSelector="{StaticResource dataFileTemplateSelector}" SelectedItem="{Binding CurrentTab, Mode=TwoWay}" >
        </telerik:RadTabControl>
 
    </Grid>
</Window>

The DataTemplate being selected is SpellRefCostAPCTemplate for the first tab and ActivityRefCostAPCTemplate for the second tab.

<DataTemplate x:Key="SpellRefCostAPCTemplate">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
 
            <telerik:RadGridView
                            x:Name="SpellDataGrid"
                            AutoGenerateColumns="False"
                            ItemsSource="{Binding DataGridViewModel.ContentData}"
                            CanUserInsertRows="True"
                            ShowInsertRow="True"
                            SelectionUnit="FullRow"
                            SelectionMode="Extended"
                            IsSynchronizedWithCurrentItem="True"
                            Grid.Row="0"
                            >
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Column1" DataMemberBinding="{Binding Column1}" />
                    <telerik:GridViewDataColumn Header="Column2" DataMemberBinding="{Binding Column2}" />
                    <telerik:GridViewDataColumn Header="Column3" DataMemberBinding="{Binding Column3}" />
                    <telerik:GridViewDataColumn Header="Column4" DataMemberBinding="{Binding Column4}" />
                    <telerik:GridViewDataColumn Header="Column5" DataMemberBinding="{Binding Column5}" />
                    <telerik:GridViewDataColumn Header="Column6" DataMemberBinding="{Binding Column6}" />
                    <telerik:GridViewDataColumn Header="Column7" DataMemberBinding="{Binding Column7}" />
                    <telerik:GridViewDataColumn Header="Column8" DataMemberBinding="{Binding Column8}" IsVisible="False" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
 
            <telerik:RadDataPager Grid.Row="1"
                              x:Name="SpellDataPager"
                              PageSize="40"
                              BorderThickness="1,0,1,1"
                              Source="{Binding Items, ElementName=SpellDataGrid}"
                              DisplayMode="FirstLastPreviousNext"
                              AutoEllipsisMode="Both"
                              NumericButtonCount="10"
                              IsTotalItemCountFixed="False" />
        </Grid>
 
 
    </DataTemplate>
 
    <DataTemplate x:Key="ActivityRefCostAPCTemplate">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
 
            <telerik:RadGridView
                            x:Name="ActivityDataGrid"
                            AutoGenerateColumns="False"
                            ItemsSource="{Binding ContentData}"
                            CanUserInsertRows="True"
                            ShowInsertRow="True"
                            SelectionUnit="FullRow"
                            SelectionMode="Extended"
                            IsSynchronizedWithCurrentItem="True"
                            Grid.Row="0"
                            >
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Column1" DataMemberBinding="{Binding Column1}" />
                    <telerik:GridViewDataColumn Header="Column2" DataMemberBinding="{Binding Column2}" />
                    <telerik:GridViewDataColumn Header="Column3" DataMemberBinding="{Binding Column3}" />
                    <telerik:GridViewDataColumn Header="Column4" DataMemberBinding="{Binding Column4}" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
 
            <telerik:RadDataPager Grid.Row="1"
                              x:Name="ActivityDataPager"
                              PageSize="40"
                              BorderThickness="1,0,1,1"
                              Source="{Binding Items, ElementName=ActivityDataGrid}"
                              DisplayMode="FirstLastPreviousNext"
                              AutoEllipsisMode="Both"
                              NumericButtonCount="10"
                              IsTotalItemCountFixed="False" />
        </Grid>
 
 
    </DataTemplate>
0
Tina Stancheva
Telerik team
answered on 12 Sep 2012, 04:14 PM
Hi David,

Please accept my apology for the delayed response. I attached a sample solution to get you started with the described scenario. Please have a look at it and let me know if it works for you or if I've missed something.

Regards,
Tina Stancheva
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.

0
David
Top achievements
Rank 2
answered on 12 Sep 2012, 10:11 PM
Hi,

Thanks that example explains exactly what I needed to know :)

Thanks

Daivd
Tags
GridView
Asked by
David
Top achievements
Rank 2
Answers by
Yoan
Telerik team
David
Top achievements
Rank 2
Tina Stancheva
Telerik team
Share this question
or