Posts Tagged C#
Cross-browser Async File Upload
Posted by Tim Valentine in General on June 18, 2014
i’ve had this post locked for years and decided to make it public. i wrote a sample to do async file uploads which took a great deal of research but never got around to writing an article for it. below you’ll see a link to zip file with the sample project in it.
WPF: Access Keys Scoping
Posted by Tim Valentine in Bug Patches, Controls, WPF on July 29, 2012
Problem
Within the WPF framework access keys are always scoped to the active window, regardless of what settings you may have set. This can cause problems when multiple elements exist within the window hierarchy. The WPF framework will likely choose the incorrect target element. What you need is to scope the access keys to the currently focused element, and unfortunately the WPF framework contains a internal bug that prevents this functionality.
Solution
WPF: Set Most Recent Input Device
Posted by Tim Valentine in WPF on July 29, 2012
Problem
You want the set the most recent input device for a particular InputManager instance.
Solution
WPF: IsSynchronizedWithCurrentItem and ICollectionView Cancel Bug
Posted by Tim Valentine in Bug Patches, Controls, WPF on November 7, 2011
Problem
As some of you may have noticed while working with a Selector-derived control and an ICollectionView, there is a bug with the IsSynchronizedWithCurrentItem property of Selector. IsSynchronizedWithCurrentItem is provided by Selector to support the ability to keep its SelectedItem in-sync with the CurrentItem of its ItemSource’s ICollectionView. IsSynchronizedWithCurrentItem works perfectly except for one specific case: when the CurrentChanging event of ICollectionView is handled and the item change is cancelled.
In this case the Selector does not respect the cancel and it gets out-of-sync with the ICollectionView. I’d imagine this bug exists because the Selector class was likely implemented before ICollectionView, and Selector was not updated to match the addition. Whatever happened though the bug does exist in WPF 4.0 and can be very problematic. Luckily, with attached properties at our disposable we can work up an easy fix.
Solution
VSTO: COM Exception 0x800A01A8
Posted by Tim Valentine in VSTO on August 20, 2011
Problem
COM exceptions that give you just a HRESULT to describe an exception are terrible. During some VSTO development for Outlook 2007, I kept getting a COM exception with an HRESULT of 0x800A01A8, and eventually I found the reason why I was receiving the exception. I though I’d share since little information is available on this particular exception.
Solution
WPF: DataGrid Select-all-button Styling
Posted by Tim Valentine in Controls, Customization, WPF on January 4, 2011
Problem
The SelectAll button on Microsoft’s DataGrid control cannot be styled without a workaround. This is a direct result of there being no SelectAllButtonTemplate property on the control. To get around this issue we’ll make our own property using attached properties. This way we can have nice, clean, MVVM-compliant code and XAML-markup, while still getting what we want.
Solution
WPF Window – Disable Minimize and Maximize Buttons Through Attached Properties From XAML
Posted by Tim Valentine in WPF on April 19, 2010
Overview
Yesterday I worked up a static helper class that encapsulates the functionality to disable/enable/toggle the minimize and maximize buttons on a standard WPF window. This morning I updated that code to fix some bugs that I overlooked. Finally just not long ago, I updated the code with a new static class called WindowCustomizer, which allows this same functionality through the use of attached properties straight from XAML-markup. The advantage here is that this is now a full MVVM-compliant solution.
Read the rest of this entry »
Dynamic Code/Class Generation (Update)
Posted by Tim Valentine in General on March 18, 2010
Overview
Back not to long ago, I released a post dealing with the dynamic generation of classes at run-time. Since then I have applied the concepts shown in that post in my real-world projects. As expected of any new code, I have found several bugs and inconveniences with the original code from that post. This time around I have an updated CodeGenerationHelper class, a DynamicFactory class, and an actual example of how to use the generated objects. The download-able version of the sample can be obtained through this link: http://thrash505.webs.com/DynamicCodeGeneration.zip
C# CodeGenerationHelper – Dynamic Classes – Create Class From Hashtable at Run-time
Posted by Tim Valentine in General on February 4, 2010
UPDATE
This post has been depreciated, for an updated version please visit: https://thrash505.wordpress.com/2010/03/18/dynamic-codeclass-generation-update/
Overview
Back a few months ago I had a class that needed (or so I thought) to be generated at run-time. The need arose from WPF controls only working with Properties, not fields, and more specifically ones that implemented INotifyPropertyChanged. (or dependency properties, but I typically save those for custom controls) After some research I created a simple straightforward helper class, CodeGenerationHelper, that would create a dynamic class at run-time from a hashtable. From a hashtable because my solution was working with data received through XML-RPC in the from of an extended hastable implementation. (XmlRpcStruct)
C# Array Casting
Posted by Tim Valentine in General on June 12, 2009
Problem
I’ve found myself in the situation where I have an array of objects that I want to cast into an array of some other type. You’d think that this would be as simple as: (TheType[])objectArray, but unfortunately, one way or another, you have to loop through each object and cast it into the new type. This becomes a pain when you need to do it frequently.
Frame-Based Animation In WPF
Posted by Tim Valentine in WPF on May 21, 2009
Problem
In WPF most animations are time-based, using storyboards to animate a objects properties over a certain period of time. That is great and works well until an artist hands you a stack of images that are to be used as individual frames of an animation. This is my current situation, so I spent an hour or two trying to figure out a way to accomplish frame-based animations in WPF. This is what I came up with…