I'd like to have a menu tool containing a dynamic list of radio button tools.
I've made a little example to illustrate the problem:
<Window x:Class="InfraSandbox.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Ribbon="clr-namespace:Infragistics.Windows.Ribbon;assembly=Infragistics3.Wpf.Ribbon.v8.2" xmlns:System="clr-namespace:System;assembly=mscorlib" Title="Window1" Height="300" Width="300"> <Window.Resources> <x:Array x:Key="data" Type="System:String"> <System:String>B1</System:String> <System:String>B2</System:String> <System:String>B3</System:String> </x:Array> </Window.Resources> <Grid> <Ribbon:XamRibbon> <Ribbon:RibbonTabItem Header="Tab"> <Ribbon:RibbonGroup Caption="Group"> <Ribbon:MenuTool Caption="MenuTool 1"> <Ribbon:RadioButtonTool Caption="A1" IsChecked="True"/> <Ribbon:RadioButtonTool Caption="A2"/> <Ribbon:RadioButtonTool Caption="A3"/> </Ribbon:MenuTool> <Ribbon:MenuTool Caption="MenuTool 2" ItemsSource="{StaticResource data}"> <Ribbon:MenuTool.ItemTemplate> <DataTemplate> <Ribbon:RadioButtonTool Caption="{Binding Path=.}"/> </DataTemplate> </Ribbon:MenuTool.ItemTemplate> </Ribbon:MenuTool> </Ribbon:RibbonGroup> </Ribbon:RibbonTabItem> </Ribbon:XamRibbon> </Grid></Window>
Is it possible to do it this way?
The items displayed in the dropdown of a menu tool aren't actually tools - not button tools anyway - they are ToolMenuItem instances. So you would have to make those menu items checkable and bind the IsChecked of the radiobuttontool to the ischecked of the menu item.
e.g.
The XAML you provided is being truncated by the forum web page. Can you repost it without lines which are very long?
All the text is there so you could just select the text in the browser and copy it into notepad/vs/etc.
Ribbon:MenuTool Caption="MenuTool 2" ItemsSource="{StaticResource data}"> <Ribbon:MenuTool.ItemContainerStyle> <Style TargetType="{x:Type Ribbon:ToolMenuItem}"> <Setter Property="IsCheckable" Value="True" /> </Style> </Ribbon:MenuTool.ItemContainerStyle> <Ribbon:MenuTool.ItemTemplate> <DataTemplate> <Ribbon:RadioButtonTool Caption="{Binding Path=.}" GroupName="mt2" IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type Ribbon:ToolMenuItem}}, Path=IsChecked, Mode=TwoWay}"/> </DataTemplate> </Ribbon:MenuTool.ItemTemplate></Ribbon:MenuTool>
Thank you.
I want to bind objects to the menu items and bind the 'IsSelected' property of my object to the check state of the menu item.
So my object has these properties: Name, IsSelected
I can use the XAML you provided and change it a bit so to bind to a list of my objects. I can get the Name property of the objects without problem using this XAML. How can I get the check state of the menu item to bind to the IsSelected property of my object in XAML?
You should be able to set the IsChecked property to a two way binding to the IsSelected of your underlying object. Probably something like:
<Setter Property="IsChecked" Value="{Binding Path=IsSelected, Mode=TwoWay}" />