I needed my WPF controls size in pixels to retrieve the correct sized image from a web service. The answer hit me one night and it’s very simple:
Create a known size image (say 100 x 100 pixels), put it in a image control on some bit of WPF screen (Hidden not collapsed), ensure no stretching [...]
Archive for the ‘.NET’ Category
WPF Screen Resolution in Pixels
Posted in .NET, WPF on April 7, 2009 | Leave a Comment »
System.Drawing.Icon and embedded rersources
Posted in .NET on September 6, 2007 | 2 Comments »
To use an icon resource embedded into your assemply:
1) Add icon to project and make it an “Embedded Resource” type (no need to copy to output directory).
2) Construct your System.Drawing.Icon like this:
new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(“MyShinyApp.hammer.ico”));
Where MyShinyApp is the value specified in “Default namespace” property of your project (Application tab of project properties) and hammer.ico is the name [...]
Minimize to tray icon in WPF
Posted in .NET on September 6, 2007 | 20 Comments »
I had to do a bit of searching so, here’s how to minimize your WPF app to a tray icon. Assume your window is called Window1 for the code below. Trap Closing, StateChanged and IsVisibleChanged (see xaml).
xaml:
<window x:Class=”MyApp.Window1″ xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
Title=”WCFAppVisualHost” Height=”383″ Width=”680″ Closing=”OnClose” StateChanged=”OnStateChanged” IsVisibleChanged=”OnIsVisibleChanged”
>
Associated cs:
private System.Windows.Forms.NotifyIcon m_notifyIcon;
public Window1()
{ // initialise code here
m_notifyIcon = new System.Windows.Forms.NotifyIcon();
[...]
Dictionary, IEquatable, Equals and GetHashCode
Posted in .NET on July 19, 2007 | 1 Comment »
The docs for the .NET Dictionary class lead you to believe that implementing IEquatable for a dictionary key is good enough to get the dictionary to use your Equals method. However, one must also override GetHashCode. Given the way a dictionary works, this is logical but not documented. The interesting part, is that the Remove [...]
Managed, Unmanaged and COM
Posted in .NET, C++, COM on July 6, 2007 | 2 Comments »
I’m wrapping a legacy lib for use in a .NET envirment.
Usefull: An Overview of Managed/Unmanaged Code Interoperability
Firstly, I tried to wrap the lib api with COM and use that from my C# app. With speed and efficiecency a priority, this was unacceptable. It involves callbacks (legacy lib) or events (COM) – the big slowdown happened in [...]
Nice! C# for_each
Posted in .NET on June 22, 2007 | Leave a Comment »
The C++ STL for_each is very useful. This C# equivalent is even better:
void Method()
{
// assuming string[] strings;
Action stringAction = delegate(string stringParam)
{
// do stuff with stringParam and whatever else available in Method()
};
Array.ForEach(strings,stringAction);
}
See other ForEaches too.
WCF
Posted in .NET on June 21, 2007 | Leave a Comment »
Platform: Vista using VS 2005.
What You Need To Know About One-Way Calls, Callbacks, And Events
The downloadable sample shows different senarios including a good example of the publisher subscriber patten.
For the samples: SQL Server is needed. Windows Vista features to turn on: IIS (including IIS Metabase and IIS 6 configuration compatibility in IIS 6 management compatibility), [...]
WPF ListView Theme
Posted in .NET on June 20, 2007 | Leave a Comment »
The Goal: To provide a theme for a standard list view.
Looking for a standard theme source for a ListView to base my theme on, I stumbled on this link: Styling with ControlTemplates Sample. It is a good basis to create a theme for anything.
ListView issues: Load up your new listview with 1000s of rows. [...]