Click here to Skip to main content
15,917,590 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I've encountered a severe problem with the RibbonComboBox: the control simply refuses to re-enable correctly and stays in a disabled state. Up to now I didn't find a proper workaround for this...

Here a small sample program to show the problem


XML
<RibbonWindow x:Class="RibbonWorkaround.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
  <DockPanel x:Name="dockPanel">
    <Ribbon x:Name="mainRibbon" DockPanel.Dock="Top" IsMinimized="False" >
      <RibbonTab Header="Tab">
        <RibbonGroup Header="Test Group">

          <RibbonButton Click="test_Click" Label="Test Button" />

          <RibbonComboBox x:Name="testSelectionCombo" SelectionBoxWidth="80">
            <RibbonGallery x:Name="testSelection"  MaxColumnCount="1" >
              <RibbonGalleryCategory x:Name="testSelectionCat" >
                <RibbonGalleryItem IsSelected="True">Test 1</RibbonGalleryItem>
                <RibbonGalleryItem>Test 2</RibbonGalleryItem>
                <RibbonGalleryItem>Test 3</RibbonGalleryItem>
              </RibbonGalleryCategory>
            </RibbonGallery>
          </RibbonComboBox>

        </RibbonGroup>

      </RibbonTab>
    </Ribbon>

    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <Button Click="Disable_Click" >Disable Ribbon</Button>
      <Button Grid.Column="1" Click="Enable_Click" >Enable Ribbon</Button>
    </Grid>
  </DockPanel>
</RibbonWindow>


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Ribbon;

namespace RibbonWorkaround
{
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class MainWindow:RibbonWindow
  {
    public MainWindow()
    {
      InitializeComponent();

    }

    private void Disable_Click(object sender,RoutedEventArgs e)
    {
      mainRibbon.IsEnabled=false;
    }

    private void Enable_Click(object sender,RoutedEventArgs e)
    {
      mainRibbon.IsEnabled=true;
    }

    private void test_Click(object sender,RoutedEventArgs e)
    {
      Console.Beep();
    }
  }
}


If you try this you'll find that the RibbonComboBox works find at first. If you select the large Disable button its disabled as you might expect. But after pressing Enable it will simply refuse to work....

Any ideas on this??


BTW: I've discovered several other problems with the RibbonComboBox control (including data binding that doesn't work properly or that the initially selected value of a data binding sometimes just doesn't show).
Posted

1 solution

found the solution... It seems that this really is a bug in the RibbonGallery control and only happens if you have installed .NET 4.6. The workaround given below does the trick.

wpf - RibbonGallery disabled in .net 4.6 - Stack Overflow[^]

C#
public MainWindow()
{
  InitializeComponent();
  testSelection.Command=ApplicationCommands.Print; // only dummy to force RibbonGallery to initialize properly
  testSelection.Command=null;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900