The project I am currently working on utilizes the Microsoft Ribbon Control for WPF. We had been running with CTP version for many months and I was finally able get my work transitioned over to the October 2010 released version.
My project does something that is pretty basic. I have a WPF graphing control on my form and a combobox on the ribbon that determines if the graph should be displayed as an area, bar, or line graph. The SelectedValue of the RibbonComboBox control is bound to a dependency property in my view model class. The graph control's "GraphType" property of my graph control is also bound to this same dependency property. Pretty basic design. When the GraphType property is changed my graph control has to actually render the graph. This ties up the UI thread. Unfortunately, doing anything on the UI thread when the property is being changed causes a problem with the RibbonComboBox control where it changes the value to the new value and then changes it BACK to the previous value!
This problem doesn't manifest itself when nothing ties up the UI thread for more than a few milliseconds (aka in all of the MS sample code). It only happens when some serious work is being done. I created a basic sample application (attached) that simulates the same problem by sleeping the UI thread for a second whenever the property that SelectedValue is bound to changes. When I tweak the amount of time that the thread sleeps downward the problem happens less frequency until it goes away. When I tweak it upwards the problem happens more frequently until it happens every time.
So what is causing this problem? I put a breakpoint on the event handler for when the dependency property that SelectedValue is bound to changes to see what is causing the change. When the problem doesn't happen this event handler is only called one time, as a result of a "LeftMouseButtonUp" event firing in the RibbonComboBox control. But when the problem does happen I see the event handler firing twice, once as a result of the "LeftMouseButtonUp" event and then a second time as a result of a "OnIsKeyboardFocusWithinChanged" event. The "LeftMouseButtonUp" event appears to change the value to the correct value, the "OnIsKeyboardFocusWithinChanged" event however appears to be setting it back to the original value.

This led me to believe that the problem may not happen if just the keyboard was used. Sure enough, if I use keytips to navigate to the RibbonComboBox and change the value then ONLY the "OnIsKeyboardFocusWithinChanged" event fires, oddly setting it to the correct new value and the problem goes away.
Here is a video that I posted to Youtube to illustrate the problem:
If I had to guess I would say that there is some sort of race condition going on whereby the engineers at Microsoft never anticipated any sort of delay on the UI thread when making a selection change with the mouse on the RibbonComboBox control. It seems like a theme these days, much of what I am seeing in WPF works great in samples and demo's but in the real world it doesn't work well at all.
Update: I found a workaround today. By creating a class of my own that inherits from RibbonComboBox and overriding the OnIsKeyboardFocusWithinChanged method I was able to prevent the second update from happening by preventing this event from being raised. The challenging thing was to prevent the second update from happening when the user used a mouse to select an item in the combobox but have it still work when the user was using the keyboard to make the selection. I discovered that the IsFocused property of the control was different, if the keyboard had made the change it was false. If the mouse made the change it was true. This enabled me to differentiate between the two and have the code work in all cases. The overriden class is as follows:
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Windows.Controls.Ribbon;
namespace RibbonComboBoxProblems
{
class RibbonComboBoxFocusFix : RibbonComboBox
{
protected override void OnIsKeyboardFocusWithinChanged(System.Windows.DependencyPropertyChangedEventArgs e)
{
if (IsFocused == false) {
base.OnIsKeyboardFocusWithinChanged(e);
}
}
}
}
VB:
Option Strict On
Imports Microsoft.Windows.Controls.Ribbon
Public Class RibbonComboBoxFocusFix
Inherits RibbonComboBox
Protected Overrides Sub OnIsKeyboardFocusWithinChanged(e As System.Windows.DependencyPropertyChangedEventArgs)
If Not IsFocused Then ' on a mouse click prevent this event from being raised as it causes the selectedvalue to change back to its old value for some reason due to a bug in the ribbon control.
MyBase.OnIsKeyboardFocusWithinChanged(e)
End If
End Sub
End Class
I have posted an item on Microsoft Connect to resolve this, if you can replicate the problem please check it out and let them know here: https://connect.microsoft.com/WPF/feedback/details/665556/ribboncombobox-selectedvalue-changes-twice
I have attached the sample code to this posting if you'd like to peruse it: RibbonComboBoxProblems.zip. I also attached the fixed version as well: RibbonComboBoxProblemsFixed.zip