RibbonComboBox selected gallery item reverts to old value on mouse leave

﹥>﹥吖頭↗ 提交于 2019-12-07 04:10:20

问题


i have replaced WPF ribbons to the newest library, the combobox selection changed triggers reload of datagrid. I have problem with the RibbonComboBox.

If i leave with mousecursor out of the selected item, the selected item is reverted to the old item. if i keep cursor on the selected item until the datagrid reload is finished, the new value is accepted to the ribboncombobox.

Do i miss some special ribboncombobox property to accept change by click only or this is a bug in the combobox component? only possible workaround would be launch datagrid reload function in thread to let the ribbon combobox finish its processes.

sample code here:

<r:RibbonComboBox>
       <r:RibbonGallery SelectedValuePath="Content" SelectionChanged="pgSize_SelectionChanged">
         <r:RibbonGalleryCategory>
            <r:RibbonGalleryItem Tag="20" Content="Size (20)" Foreground="Green" />
            <r:RibbonGalleryItem Tag="30" Content="Size (30)" Foreground="Green" IsSelected="True"/>
            <r:RibbonGalleryItem Tag="50" Content="Size (50)" Foreground="Orange" />
            <r:RibbonGalleryItem Tag="100" Content="Size (100)" Foreground="Red" />
         </r:RibbonGalleryCategory>
       </r:RibbonGallery>
</r:RibbonComboBox>      

回答1:


This is a bug in the ribbon control. See the Connect bug report.




回答2:


The following provides a functioning workaround (.Net 4.0), based on the workaround given in the Connect Bug.

I found you only need the Mouse.Capture(null) on the SelectionChanged event:

<ribbon:RibbonComboBox>
    <ribbon:RibbonGallery SelectedItem="{Binding X}"
                          DisplayMemberPath="Name"
                          SelectionChanged="RibbonGallery_SelectionChanged">
        <ribbon:RibbonGalleryCategory ItemsSource="{Binding Y}"
                                      DisplayMemberPath="Name" />
    </ribbon:RibbonGallery>
</ribbon:RibbonComboBox>

With the following code behind:

void RibbonGallery_SelectionChanged(
    object sender,
    RoutedPropertyChangedEventArgs<object> e)
{
    Mouse.Capture(null);
}

Or, as a derived class:

/// <summary>
/// Fixes a known issue with the <see cref="RibbonGallery"/>.
/// </summary>
/// <remarks>
/// See <a href="https://connect.microsoft.com/VisualStudio/feedback/details/666352/">Allow users to move mouse after selecting an item in WPF RibbonComboBox</a>.
/// </remarks>
public class RibbonGalleryEx : RibbonGallery
{
    public RibbonGalleryEx()
    {
        this.SelectionChanged += (sender, e) => Mouse.Capture(null);
    }
}


来源:https://stackoverflow.com/questions/3998655/ribboncombobox-selected-gallery-item-reverts-to-old-value-on-mouse-leave

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!