Jul 29 2009

How to set the windows position in WPF

Category: WPF | C#fossmo @ 17:18

To position a window manually on the screen in Window Presentation Foundation you can use these system properties Window.Left and Window.Top. To get the size of the screen you can use these system properties:

System.Windows.SystemParameters.PrimaryScreenWidth;
System.Windows.SystemParameters.PrimaryScreenHeight;

To set a window (the green one) position like the one shown at the image below, you can use this method:

private void SetWindowPosition()
{
    Left = SystemParameters.PrimaryScreenWidth - (double)GetValue(WidthProperty) - 30; ;
    Top = 150;
}

image

Tags:

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Jul 5 2009

Converting from SVG to XAML

Category: WPF | Softwarefossmo @ 19:22

To night I spent hours trying to convert from a SVG file to XAML. The reason for wanting to do the converting, is that I want a vector based image in a WPF application I’m currently developing. Using a vector based image will scale much better than using a bitmap image.

imageThe solution

I first downloaded a vector based image from this url: http://iconeden.com/icon/free/get/milky-a-free-vector-iconset
Inside the zip file you will find a SVG file. You can open this file using Adobe Illustrator, but I prefer using free alternatives, so I downloaded Inkscape. Inkscape is a open source vector graphics editor. I opened the file, and it contained several images. I wanted one of them; a clock. I copied and pasted the image into a new instance of Inkscape. If you choose Save as from the file menu in Inkscape, you will notice that I gives you the option to save as XAML. I tried doing that without success. It turned out that the XAML produced by Inkscape is not valid when opening it in Expression Blend or Visual Studio. So I saved the file as Clock.svg

On Codeplex there’s a project called XamlTune. I downloaded it and used the command prompt tool called svg2xaml.exe found in the package. The output from this small application were a XAML file called Clock.xaml. I opened this file in Visual Studio and guess what? It worked. The image were converted from SVG to XAML without any errors.

If you need to convert from SVG to XAML, I recommend that you look at this tool. I have only used it a few time, but it looks good so fare.

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Jul 2 2009

A great book to get you started with NHibernate

Category: Administrator @ 15:13

Lately I have tried to learn NHibernate. NHibernate is a object-relational-mapper. It maps data from relational databases to POCO-objects. So, what is useful about that, you may ask? Well, for a starter, it’s very handy when creating a rich domain model. If you read this blog regularly, you may know that I’m also in the process of learning Domain Driven Design.

Domain Driven Design and NHibernate

The idea behind DDD is that you focus on the domain model instead of focusing on the database or GUI when trying to capture the business value from a domain expert. If you follow the guidelines described in the books written by gurus on the topic, you will end up with a domain model that is loosely coupled from the other parts of the system you are creating. That means you don’t have a coupling against the GUI, the database or any other parts of the system. But, you still need to persist the data from the domain model to the database in some way, and this is where NHibernate comes in to play. By setting up a mapping, described in a file, from the domain model to the database you can make NHibernate do the mapping for you. How cool is that? I guess you knew that already, but the purpose of this post is not to tell you how cool NHibernate is, but to guide you in the right direction of how to start learning NHibernate.

How I learned it

image

My first approach to learning NHibernate was to look at the excellent screen casts made by Stephen A. Bohlen called Summer of NHibernate. I learned a lot from watching these screen casts, but I still felt like something were missing. It’s like when you go to a conference, at the end of the day you can’t sit down in front of the PC and start to crank out code based on what you learn that day. But, it gives you a starting point. You often get information of how to investigate the topic further. This is what Summer of NHibernate did for me and it pointed me in the direction of a book called NHibernate in action.

Beside giving you a good start on setting up and using NHibernate, it also explains how to write real-world domain models. It tells you how to set up pretty complex associations between entities and why it’s important to understand why a domain model should be persistence ignorant and so on and so fourth. If you want to have a look at the index of the book, it can be found at this link.

If you want to learn NHibernate you definitely should look at this book.

Links

Links to NHibernate resources I have used and use:

- Summer of NHibernate (screen casts)
- Dimecasts.org have some screen casts on the topic (max 10 minutes long)
- NHibernate in action (excellent book on the topic)
- NHibernate.org (You can download the binaries from this site and you find documentation)

Happy learning!

Tags:

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Jul 1 2009

My TortoiseSVN global ignore pattern

Category: source controlfossmo @ 16:32

I’m a big fan of Subversion and I love using TortoiseSVN. Many people prefer AnkSVN over TortoiseSVN because it integrates with Visual Studio, but I feel like I have more control over what’s happening when I’m using TortoiseSVN. Every time I set up a computer for development I have to add a ignore pattern to separate the files I want to check in from the ones I don’t want to check in.

This is my global ignore pattern:

*ReSharper* *.suo *resharper* *Debug* *Release* *.user *.bak

To add this pattern to TortoiseSVN follow these steps:

Right click in Explorer –> Choose TortoiseSVN –> Choose Settings –> Under ‘Global ignore pattern’ add the pattern.

 

image

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5