Yet another coding blog covering everything from C#, WPF, SQL, and Silverlight to any other random thought that passes my way…
RSS icon Home icon
  • Videos not showing in the dialog in the Seesmic Desktop Video Preview plugin

    Posted on June 28th, 2010 biggert No comments

    Just a quick mention about a problem a few people have had when attempting to view the videos in my Seesmic Desktop Video Preview plugin. The users will click the video and the dialog will open to an empty box. This happens when you don’t have Adobe Flash player installed for IE. The dialog box that shows the video uses a Silverlight WebBrowser component which is actually just a IE-wrapper… so if you don’t have Flash installed for IE or you have it disabled in IE, the videos in Seesmic won’t show…. so just fix your IE and you’ll fix your Seesmic :)

    Go here to download the Seesmic Desktop Video Preview plugin.

  • WPF Datagrid and the dreaded double-tab focus issue

    Posted on November 24th, 2009 biggert 5 comments

    So I just had to figure this out on my own over the last hour or so and found it to be a good candidate for a post. I found my path through the internet on this one but apparently everyone’s solution didn’t exactly equal to mine for some reason or another. So here we go:

    Problem:

    When using a DataGridTemplateColumn from the DataGrid in the WPF Toolkit in .NET 3.5 (after attending PDC09, I know .NET4 will have a built-in WPF DataGrid), if you want to simply use tab to change the focus between controls within the cells, you’ll have to double-tab to move to the next control.

    For example, if I have a textbox in a cell and want to move to a textbox in another cell within the datagrid with TAB, hitting TAB once will move me to the next DataGridCell… then I have to press TAB again to move to the TextBox inside that DataGridCell.

    Solution:

    After googling around, I frequently hit this site which supposedly fixed this problem with a nice little solution: http://blog.yalovoi.net/2009/08/21/

    For some reason unknown to me and not worth my time to investigate, it doesn’t work at all. Here’s what I came up with which is uglier but, in my case, works. I simply navigate the tree from the DataGrid to the textbox.

    Forgive my quick and dirty coding but it gets the job done… I’m sure you could easily spawn a much more generic code to do this:

            private void uxFieldMappingsDataGrid_CurrentCellChanged(object sender, EventArgs e)
            {
                uxFieldMappingsDataGrid.BeginEdit();
            }
    
            private void uxFieldMappingsDataGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
            {
                ContentPresenter cp = (ContentPresenter)e.EditingElement;
    
                TextBox destinationTextBox = VisualTreeHelper.GetChild(cp, 0) as TextBox;
    
                if (destinationTextBox != null && destinationTextBox.Name == "uxTest")
                {
                    destinationTextBox.Focus();
                }
            }
    

    You can see where I climb the visual tree down to the text box. Very simple code for a very specific reason that I’m sure you can mold to make your own if you find that you are having the same problems as I am (and using code-behind to solve it isn’t against your religion).

  • Can’t figure out how to implement a custom IDataReader to my collection

    Posted on October 22nd, 2009 biggert No comments

    I hope someone can help me here… I’ve been working on this for 4 days now with barely any luck.

    Here’s the question:

    I know it is possible to create a custom datareader (inferring from the IDataReader interface) which accesses the data in a collection. I’ve seen it used in other third-party controls and am wanting to do it myself. I’ve come across an ancient (2004) website of how a guy explains how to do it (http://blogs.msdn.com/yvesdolc/archive/2004/11/08/254209.aspx) but I am having difficulty implementing his code since he did not provide examples and 2004 C#/.NET2.0 might not be as performance-tuned as the latest and great C#/.NET3.5. Can anyone assist me in either providing some samples on how to do this or providing some sources that can teach me how to do this. I’m googled up and down on a tutorial on how to write a custom datareader but everything I find isn’t very helpful… it either lists code that’s already complete without good information of how they got there or has code that doesn’t do what I need it to do.

    Just to make it easy, I’ve included an example collection in the code so that, if examples are provided, they can reference it.

    NOTE: Just an additional item, if this can be generic-ized in a way to support different types of collections, that’s a huge plus!

    public class Person
    {
         public int ID {get; set;}
    
         public string Name {get; set;}
    
         public string Gender {get; set;}
    
         public Person()
         {
    
         }
    
         public Person (int id, string name, string gender)
         {
    
              ID = id;
              Name = name;
              Gender= gender;
         }
    }
    
    public class People : List
    {
         public People { };
    }
    
    public void Main()
    {
         Person person1 = new Person(1, "John Doe", "Male");
         Person person2 = new Person(2, "Jane Smith", "Female");
         Person person3 = new Person(3, "Tom White", "Male");
    
         People peeps = new People();
    
         peeps.Add(person1);
         peeps.Add(person2);
         peeps.Add(person3);
    
    }
    

    UPDATE (10/29/2009): Well, I figured out a way to get his code and it was well worth the effort as I noticed an increase in performance (as well as a significant decrease in MEM usage) when using his datareader over converting to a datatable. I’m busy coding away at it and I having yet figured out how to keep it as generic as I’d like but his code works well for now. I’ll post the solution (using his code) at a later date so everyone can see. It’s actually quite simple….

  • Update to previous mystery WPF issue

    Posted on May 6th, 2009 biggert No comments

    Just wanted to make it obvious that I’ve updated the previous post about the mystery WPF issue regarding a strange crash. I wouldn’t really call it a solution… more of a workaround for our systems. Let’s hope it holds up in the long run (or at least until this issue is addressed by Microsoft, which probably won’t happen anytime soon since they haven’t responded to any requests).

  • Mystery WPF problem that I need help with…

    Posted on April 20th, 2009 biggert 1 comment

    I didn’t want to do this so early in the life of this site but I’m at a loss of what to do. We’ve got a heavy WPF application which has a nice little animated progress spinner on it using WPF animation (DoubleAnimation). The problem is basically laid out here: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a4b2df90-8fa3-4b59-9242-9c48000fa62a. As you can see, there’s no answers yet and it’s been out there since March. We are seeing this randomly occur in our application and I have identified the source POSSIBLY being the progress spinner’s infinite animation (we turned the animation off and don’t see the problem again… yet).

    Here’s our stacktrace. As you can see there, is not specific source to OUR code… it’s all WPF internals… and this happens completely randomly at random intervals and is not reproduceable on some machines. I appreciate any help that can be provided.

    ===================================

    Unhandled exception detected in application. Please see technical details for more information: UIElement.Measure(availableSize) cannot be called with NaN size.

    ===================================

    UIElement.Measure(availableSize) cannot be called with NaN size. (PresentationCore)

    ——————————

    Program Location:

    at System.Windows.UIElement.Measure(Size availableSize)

    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

    at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

    at System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

    at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.Border.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.Control.MeasureOverride(Size constraint)

    at Microsoft.Windows.Controls.DataGrid.MeasureOverride(Size availableSize)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

    at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

    at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.Control.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

    at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

    at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

    at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.Control.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

    at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.Border.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.Controls.Page.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

    at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

    at System.Windows.UIElement.Measure(Size availableSize)

    at System.Windows.ContextLayoutManager.UpdateLayout()

    at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)

    at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()

    at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()

    at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)

    at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)

    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

    EDIT: Grrr.. even with the animations off, there’s still a problem. Here’s a new stacktrace:
    ===================================

    Unhandled exception detected in application. Please see technical details for more information: TimeSpan does not accept floating point Not-a-Number values.

    ===================================

    TimeSpan does not accept floating point Not-a-Number values. (mscorlib)

    ——————————
    Program Location:

    at System.TimeSpan.Interval(Double value, Int32 scale)
    at System.Windows.Media.MediaContext.ScheduleNextRenderOp(TimeSpan minimumDelay)
    at System.Windows.Media.MediaContext.EstimatedNextVSyncTimeExpired(Object sender, EventArgs e)
    at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

    EDIT: Just wanted to update everyone on how we minimized this issue. From the MSDN forums, the only common link we could find is our development machine hardware/software. The only conclusion we could come up with is a WPF incompatibility between our hardware and/or software. We added an app settings flag that is checked before any infinite animations are executed and that flag is set to true to disable the animations on our development machines but set to false during deployment. This gives us access to enable/disable this feature if we ever see it occur on client computers (which we hope does not happen!).