启用功能区后,RibbonComboBox(WPF)保持禁用状态 [英] RibbonComboBox (WPF) stays disabled after enabling the Ribbon

查看:141
本文介绍了启用功能区后,RibbonComboBox(WPF)保持禁用状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在RibbonComboBox上遇到了一个严重的问题:该控件只是拒绝正确重新启用并保持禁用状态.到目前为止,我还没有找到合适的解决方法...

这里有一个显示问题的小示例程序


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


<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>





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();
    }
  }
}



如果您尝试此操作,首先会发现RibbonComboBox可以正常工作.如果选择较大的禁用"按钮,则可能会禁用它.但是在按下启用后,它只会拒绝工作....

有什么想法吗?


顺便说一句:我发现了RibbonComboBox控件的其他一些问题(包括数据绑定无法正常工作或数据绑定的初始选择值有时不显示).



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).

推荐答案

找到了解决方案...看来这确实是RibbonGallery控件中的错误,并且只有在安装了.NET 4.6的情况下才会发生.下面给出的解决方法可以解决问题.

wpf-.net 4.6中的RibbonGallery已禁用-堆栈溢出 [ ^ ]

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[^]

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


这篇关于启用功能区后,RibbonComboBox(WPF)保持禁用状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆