Enrique posted on May 20, 2010 22:15

I saw this question on Stackoverflow

WPFToolkit DataGrid: Combobox column does not update selectedvaluebinding immediately

We had this problem some time ago, and to understand the issue we need to recap a little bit, things happens give or take on this order:

  • 1-The user select the cell

  • 2-change the combobox selection

  • 3-the user leave the cell

So, what about the events being fired? I'm pretty sure the one you are interested in is the ComboBox_SelectionChanged right? but the question is WHEN this event is being fired? so let me go straight to the point, I'll use the steps about

  • 1-The user select the cell THE CELLS GOES INTO EDIT MODE

  • 2-change a value THE ComboBox_SelectionChanged IS FIRED BUT THE CELL STILL IN EDIT MODE AND NO CHANGES ARE PERFORMED-

  • 3-the user leave the cell AND THE CHANGES ARE COMMITTED !!

as you can realize the changes are committed only when the cell loses its focus and leave the editing mode, the solution is to commit the changes on the ComboBox_SelectionChanged event, so lets implement our own column type called AutoCommitComboBoxColumn :

here is the code:

 public class AutoCommitComboBoxColumn : Microsoft.Windows.Controls.DataGridComboBoxColumn
    {
        protected override FrameworkElement 
           GenerateEditingElement(Microsoft.Windows.Controls.DataGridCell cell, object dataItem)
        {
            var comboBox = (ComboBox)base.GenerateEditingElement(cell, dataItem);
            comboBox.SelectionChanged += ComboBox_SelectionChanged;
            return comboBox;
        }

        public void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CommitCellEdit((FrameworkElement)sender);
        }
    }

Now  go ahead and use this column instead of the default DataGridComboBoxColumn and  give it a try.

 


Posted in: WPF  Tags:
Enrique posted on January 13, 2010 13:07

I’m going to quickly post the solution to this issue since its late ..or too early 5:41 a.m EST  basically when working with WPF using  CAL-PRISM- or whatever you want to call the Composite Application Guidance for WPF and Silverlight and you want to show a popup window you may want to use the WindowRegionAdapter from the WPF Contrib project   the problem is when you close the windows you may have the exception {"Cannot change ObservableCollection during a CollectionChanged event."}

 

private void window_Closed(object sender, EventArgs e)
{
Window window = sender as Window;
IRegion region = _regionWeakReference.Target as IRegion;
if (window != null && region != null)
if (region.Views.Contains(window.Content))
region.Remove(window.Content);//exception
                                             //Cannot change ObservableCollection 
                                             //during a CollectionChanged event."} 
}

 

 

 

I have made some changes to WindowRegionAdapter.cs in order to fix it and seems to be working, here are the changes:

add:

using System.Threading;
replace the  window_Closed  code for the code below:
 
class CloseWindwowCallbackParameter
{
    public IRegion theRegion { get; set; }
    public Window windowToClose { get; set; }
}
private void closeWindowinThread(object parameters)
{
    CloseWindwowCallbackParameter arguments = parameters as CloseWindwowCallbackParameter;
    IRegion region = arguments.theRegion;
    Window window = arguments.windowToClose;
    window.Dispatcher.Invoke(
                       System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
  {
      region.Remove(window.Content);
  }));
 
}
 
private void window_Closed(object sender, EventArgs e)
{
 
    Window window = sender as Window;
    IRegion region = _regionWeakReference.Target as IRegion;
    if (window != null && region != null)
        if (region.Views.Contains(window.Content))
        {
            WaitCallback callback = new WaitCallback(closeWindowinThread);
            ThreadPool.QueueUserWorkItem(callback, new CloseWindwowCallbackParameter 
                                                 {theRegion = region, windowToClose = window });
        }
}


Posted in: WPF  Tags: , ,
Enrique posted on October 14, 2009 22:25

If you downloaded the RibbonControlsLibrary.dll  and having a hard time, for example I was having this error:

Undefined CLR namespace. The ‘clr-namespace’ URI refers to a namespace ‘Microsoft.Windows.Controls.Ribbon’ that is not included in the assembly.

you should read the comments found at the bottom of this post:

http://teusje.wordpress.com/2009/08/12/wpf-office-ribbon-control/

basically the dll is being blocked by the OS and visual studio is unable to load and use it, the solution is right click on the file and unblock it; after that  you may need to recreate(add\delete) the reference or\and open/close the solution again.

image

image


Posted in: WPF  Tags: , ,

If you are having the “'This TextNavigator' has no scoping text element.” exception working with the richtextbox control in WPF, probably you are manipulating the xaml "manually” and, at least in my case,  because an empty BlockUIContainer block.


Posted in: WPF  Tags: , ,

Calendar

«  September 2010  »
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
View posts in large calendar

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 BizTalkAnd .Net