Feeds:
Posts
Comments

Archive for the ‘.NET’ Category

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 [...]

Read Full Post »

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 [...]

Read Full Post »

Minimize to tray icon in WPF

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();
    [...]

Read Full Post »

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 [...]

Read Full Post »

Managed, Unmanaged and COM

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 [...]

Read Full Post »

Nice! C# for_each

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.

Read Full Post »

WCF

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), [...]

Read Full Post »

WPF ListView Theme

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. [...]

Read Full Post »