chris mylonas blog
There is only one good, knowledge, and one evil, ignorance - Socrates
2014-12-19
Eclipse ADT woes
2008-12-03
WPF applications and CA2104 rule
If you are using static fields such as:
public static class Constants
{
public static readonly FontFamily MyFontFamily = new FontFamily("Segoe UI");
}
with “{x:Static}” markup extensions such as:
FontFamily="{x:Static this:Constants.MyFontFamily }"
you will get the following warning:
CA2104 : Microsoft.Security : Remove the read-only designation from 'Constants.MyFontFamily' or change the field to one that is an immutable reference type. If the reference type 'FontFamily' is, in fact, immutable, exclude this message.
If you remove the “readonly” modifier you get a different warning:
CA2211 : Microsoft.Usage : Consider making 'Constants.MyFontFamily' non-public or a constant.
In order to solve the problem convert the field, to a property with get accessor only, such as:
public static FontFamily MyFontFamily
{
get
{
return new FontFamily("Segoe UI");
}
}
2008-09-20
2008-09-05
Quick way to rename objects on WinForms with Visual Studio
- Open the windows forms designer.
- Open the Document Outline (View|Other Windows|Document Outline)
- Select the objects using Document Outline and rename them using F2 (edit)
Better than renaming from Properties window?
Vista and Bluetooth Headsets
I decide to pair my Nokia BH-208 Bluetooth headset with my Compaq NX8220 laptop (running Vista Business SP1) to watch some cool videos from mix conference. I open the headset, enable the wireless and Bluetooth device and try to pair the headset. BUT the headset is not list of devices. Why? I try to understand what is going on.
A quick search on the web provides the answer.
Windows Vista RTM doesn’t support Bluetooth headsets. They include the functionality in beta versions, but they removed in RTM versions. This also includes the SP1 release which is already installed in my laptop.
I am pissed off, and decide to found a solution.
- I found that Microsoft release Windows Vista Feature Pack for Wireless for OEM vendors only, and not for general public, but the update can be found on the internet.
I download and installed it. Beware that feature pack requires SP1. - Download and install the Bluetooth device drivers from HP because headset is a Bluetooth Peripheral Device and Vista needs drivers for this.
After that the headset appears in the list of devices and paired successfully.
2008-03-20
2008-03-13
Great blog for WPF Data Binding
2007-12-13
Wallpaper Generator
Download the application from here.
FlowDocument and multiple threads
The refresh button clears the contents of the documentPanel, and creates and displays a random number of flow documents.
This works as expected and creates a random number of flow documents on window.
My next step is to make this work in asynchronous manner. How is that possible? Enter DispatcherObject and WPF Threading model.
The basic technique is to use the Dispatcher methods and delegates to do the heavy operations in a different thread.
To demonstrate this, I create a new "Refresh Async" button and modify the flow document creation to include a 5 sec Sleep.
The next step is to add the delegate and dispatcher calls. The refresh async button handler uses the Dispatcher to asynchronously call the GenerateAndShowFlowDocumentHandler method which creates and displays the flow document.
This also works fine.
The next step is to create the FlowDocument in a separete thread and use the main UI thread for UI update.
When I try this I get exceptions!.
To resolve this issue, I should serialize the FlowDocument as Memory stream since FlowDocument's seems that they can’t serialize themselves on different threads.
Add the following before passing the flow document.
And to the handler :
And it works great!!