Posted 13 years ago
by Robert Croshere
Version: 11.1.0545
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
Hi, in the ribbon we have, a certain menu can be accessed from different places (including contextual tabs). As I don't want to define the menu mulitple times (due to maintenance), I decided to add the menu as a resource. I can't just add the menu as a StaticResouce, as the element can't be rooted multiple times. So I created a style as follows:
As can be seen, the menu is always displayed in a popupbutton, so I'm setting the template for the popup here. This approach works, but leaves me with two problems:
1 - The first time the menu shows, all colors in the gallery are placed on a single line, thus creating an incredibly wide menu. The second time the menu is shown is appears ok.
2 - When all commands on the menu are disabled, the popupbutton itself is still enabled, even though the command is set to NotACommand.
How can I get rid of these problems?
Regards,
Robert Croshere
<!-- Contents of the border menu -->
<Style
x:Key="borderMenuStyle"
TargetType="ribbon:PopupButton">
<Setter
Property="Command"
Value="NotACommand" />
<Setter
Property="Label"
Value="{x:Static props:Resources.RibbonMenuCaptionOutline}" />
<Setter
Property="ImageSourceSmall"
Value="../Images/FormatBorderMenu16.png" />
<Setter
Property="ImageSourceLarge"
Value="../Images/FormatBorderMenu32.png" />
<Setter
Property="PopupContentTemplate">
<Setter.Value>
<DataTemplate>
<ribbon:Menu>
<ribbon:ColorPickerGallery
Command="{Binding ControlCommands.FormatBorderFill}"
IsPreviewEnabled="True"
InitialColumnCount="10"
HorizontalAlignment="Center"
CategorizedItemsSource="{StaticResource colorPickerColors}">
<ribbon:ColorPickerGallery.CommandParameter>
<self:BrushValueCommandParameter />
</ribbon:ColorPickerGallery.CommandParameter>
</ribbon:ColorPickerGallery>
<ribbon:Button
Command="{Binding ControlCommands.ResetBorder}" />
<ribbon:Separator />
<ribbon:Button
Label="{x:Static props:Resources.RibbonButtonCaptionMoreColors}"
Command="{Binding ControlCommands.FormatBorderFill}"
CommandParameter="{x:Null}"
ImageSourceSmall="../Images/MoreColors16.png" />
<ribbon:PopupButton
Command="NotACommand"
Label="{x:Static props:Resources.RibbonMenuCaptionWeight}"
ImageSourceSmall="../Images/BorderWeightMenu16.png">
<ribbon:PopupGallery
Command="{Binding ControlCommands.FormatBorderWeight}"
IsPreviewEnabled="True"
UseSingleColumn="True"
VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding Source={StaticResource borderWidths}}">
<ribbon:PopupGallery.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="Auto" />
<ColumnDefinition
Width="Auto" />
</Grid.ColumnDefinitions>
<Line
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
X1="0"
X2="100"
Y1="{Binding Converter={StaticResource mathConverter}, ConverterParameter=-2}"
Y2="{Binding Converter={StaticResource mathConverter}, ConverterParameter=-2}"
StrokeThickness="{Binding}"
Stroke="Black" />
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
Margin="7,3,3,3"
Text="{Binding}" />
</Grid>
</DataTemplate>
</ribbon:PopupGallery.ItemTemplate>
<ribbon:PopupGallery.CommandParameter>
<self:DoubleValueCommandParameter />
</ribbon:PopupGallery.CommandParameter>
</ribbon:PopupGallery>
</ribbon:PopupButton>
<ribbon:PopupButton
Command="NotACommand"
Label="{x:Static props:Resources.RibbonMenuCaptionStyle}"
ImageSourceSmall="../Images/BorderStyleMenu16.png">
<ribbon:PopupGallery
Command="{Binding ControlCommands.FormatBorderStyle}"
IsPreviewEnabled="True"
UseSingleColumn="True"
VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding Source={StaticResource borderStyles}}">
<ribbon:PopupGallery.ItemTemplate>
<DataTemplate>
<Grid
MinHeight="18">
<Line
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
X1="0"
X2="100"
Y1="0"
Y2="0"
StrokeThickness="2"
Stroke="Black"
StrokeDashArray="{Binding Converter={StaticResource ReportBorderStyleToStrokeDashArrayConverter}}" />
</Grid>
</DataTemplate>
</ribbon:PopupGallery.ItemTemplate>
<ribbon:PopupGallery.CommandParameter>
<self:ObjectValueCommandParameter />
</ribbon:PopupGallery.CommandParameter>
</ribbon:PopupGallery>
</ribbon:PopupButton>
</ribbon:Menu>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
1 - The first time the menu shows, all colors in the gallery are placed on a single line, thus creating an incredibly wide menu. The second time the menu is shown is appears ok.
2 - When all commands on the menu are disabled, the popupbutton itself is still enabled, even though the command is set to NotACommand.
How can I get rid of these problems?
Regards,
Robert Croshere