Hi,
on my data grids I have implemented the functionality to do an save and load the layout, reset the layout to default and to do an export to Excel. This is done by a ContextMenu defined in a style, which works fine.
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Export to Excel" Command="{Binding ExportToExcelCmd}" CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type ContextMenu}}}">
<MenuItem.Icon>
<Image Source="/Resources/Icons/Excel.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Save grid layout" Command="{Binding SaveDataGridLayoutCmd}" CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type ContextMenu}}}">
<MenuItem.Icon>
<Image Source="/Resources/Icons/Save.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Load grid layout" Command="{Binding LoadDataGridLayoutCmd}" CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type ContextMenu}}}">
<MenuItem.Icon>
<Image Source="/Resources/Icons/Refresh.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Reset grid layout" Command="{Binding ResetDataGridLayoutCmd}" CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type ContextMenu}}}">
<MenuItem.Icon>
<Image Source="/Resources/Icons/Refresh.png" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Setter.Value>
</Setter>
Recently I discoverd the ControlPanel control. I copied/paste the code from the demo to implement the show/hide columns feature. Now I would like to switch from the above ContextMenu to a ControlPanel with buttons for each action:
<telerik:ControlPanelItemCollection>
<telerik:ControlPanelItem ButtonTooltip="Column chooser" >
<telerik:ControlPanelItem.ContentTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding Columns}" BorderThickness="0">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Header, Mode=OneWay}" IsChecked="{Binding IsVisible, Mode=TwoWay}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</telerik:ControlPanelItem.ContentTemplate>
</telerik:ControlPanelItem>
<telerik:ControlPanelItem ButtonTooltip="Save/Load layout" >
<telerik:ControlPanelItem.Content>
<ListBox>
<Button Content="Export to Excel" Command="{Binding ExportToExcelCmd}" CommandParameter="{Binding ?"/>
<Button Content="Save grid layout" Command="{Binding SaveDataGridLayoutCmd}" CommandParameter="{Binding ?}"/>
<Button Content="Load grid layout" Command="{Binding LoadDataGridLayoutCmd}" CommandParameter="{Binding ?}"/>
<Button Content="Reset grid layout" Command="{Binding ResetDataGridLayoutCmd}" CommandParameter="{Binding ?}"/>
</ListBox>
</telerik:ControlPanelItem.Content>
</telerik:ControlPanelItem>
But I'm stuck with the binding of the Command. As I'm using the MVVM pattern, the Command is bound to a command in my ViewModel. This works fine for the ContextMenu, but not for the ControlPanel.
Also, the datagrid itself needs to be send as a parameter with the command and I'm not sure how to do this.
Any help would be much appreciated.
Regards,
Hans