开发者

RibbonComboBox selected gallery item reverts to old value on mouse leave

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 Selec开发者_运维技巧tedValuePath="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>      


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜