BrownBot Logo BrownBot Head

WPF Nav App With Added ZOOM

10:33 pm Filed under: C#,WPF

Here are the results of today’s work:

  • added some zoom controls on the list and detail views.
  • added scroll viewers for the zoomable parts so they behave nicely at the extremes and don’t zoom the clickable controls.
  • Standardized the detail views to 300px so the edit wrap panel looks good and the read only view can scale properly.
  • general cleaned up and lined up of all the elements and borders.

So now it looks like:

SearchSmall SearchLarge

EditSmall EditLarge

Much better, I’ve still got a ways to go on it, one standard feature I know the users are going to ask for is sorting by the grid header (the main reason the current client is still in Delphi 7)… not so easy to implement, I’m thinking some sort of encoded ButtonBase.Click event that passes a parameter through to the ViewModel and some Linq might be the go.

I’ll keep plugging away.

WPF Nav App Design Considerations

4:42 pm Filed under: C#,WPF

I had a great design session yesterday styling up the navigation/view/model app framework I’ve been designing as the basis for the administration program at the mill.

One thing I’m still struggling with is how to effectively handle the huge difference in screen real estate between 1024×768 and 1680×1050.. more than twice the pixels on the screen. The challenge is to not just to make it look half decent but to actually utilise the extra space for displaying data.

Who knows what res we’ll be running in 5 years time?

This is my first draft, my Widget object only has a hand full of fields so really struggles at high res.

Search/Select Screen

SearchSmall SearchLarge

Edit Screen

EditSmall EditLarge

I’m happy with the 3D grey tones, I think I’ve struck a nice balance between looks a function, everything white is pure data, anything intractable is bordered in mid Grey, anything darker is background. I don’t think it’s too heavy, the grays aren’t that far off your standard windows schemes.

With the edit screen I tried a set width on the group borders in a WrapPanel instead of a stack panel, I think that coupled with some zoom controls might be the ultimate solution.

More to come.

Render System.Drawing.Image in WPF

6:36 pm Filed under: C#

I’ve been working on a ViewModel style framework for a big project coming up at work, I decided to add a little spice to the test “Widget” and “Dirchie” objects by including an Image property that loads and saves to the database.

As it turns out it added plenty of spice as it’s not the easiest thing to pull off. Anyhow I eventually got the DB provider loading and saving a standard System.Drawing.Image object, only to find out you can’t actually use it natively in WPF.

Here’s the value converter I wrote to do the conversion for me (the code was adapted from this sample).

using System;
using System.Windows;
using System.Text;
using System.Windows.Data;
using System.Globalization;
using System.Windows.Media.Imaging;
using System.Windows.Interop;
using System.Drawing;

namespace Qaf
{
    [ValueConversion(typeof(Image), typeof(BitmapSource))]
    public class ImageToBitmapSourceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Image val = (Image)value;

            Bitmap bitMap = new Bitmap(val);
            return Imaging.CreateBitmapSourceFromHBitmap(bitMap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new InvalidOperationException("This should not be called");
        }
    }
}

Colour from Angle

5:28 pm Filed under: C#,XNA

The other day I converted a formula I found on Wikipedia into XNA C# code, basically I wanted to turn the 360 degree direction of a controller stick into a pure colour hue.

It’s a bit of a weird formula but it works a treat.

public static Color ColourFromAngle(float angle)
{
    float a = angle / 60.0f;
    int h1 = (int)a;
    int h = h1 % 6;
    float f = a - (float)h1;
    float p = 0;
    float q = 1.0f - f;
    float t = 1 - (1 - f);

    switch (h1)
    {
        case 0: return new Color(new Vector3(1, t, p));
        case 1: return new Color(new Vector3(q, 1, p));
        case 2: return new Color(new Vector3(p, 1, t));
        case 3: return new Color(new Vector3(p, q, 1));
        case 4: return new Color(new Vector3(t, p, 1));
        case 5: return new Color(new Vector3(1, p, q));
    }
    return Color.Red;
}

WCF Work Environment

10:53 pm Filed under: C#

Pick up another monitor the other day to help me with this WCF client server development work I’m doing, one extra screen turned the job from a pain in the arse into a pleasure.

The picture below shows the server and console test app running from the PC underneath on the left hand screen and two instances of the client running from the laptop on the right hand screen.

The server has a timer in it which simulates production (the real reporting of production is the next job), the clients take these status updates and tick off the batches, the UI automatically updates via the data binding.

WCF Development Environment

Next week I’ll be going back to the start of the app and checking what I’ve broken with the more recent changes and re-factoring some of the more curly bits of the UI code.

Dipping a toe into the WCF pond

2:58 pm Filed under: C#

Spent the day in WCF yesterday, plenty of reading and then hacked up a couple of different samples I found around the web into a basic but functional client server test.

What I set out to achieve was write a simple service that clients could connect to and receive a callback from, previously I’ve done this by having the client poll a server on a timer which is really inefficient. The screen shot below shows the server console on the left spewing out updates every 100 milliseconds and the 5 clients on the right instantly receiving the message.

image

Not all that impressive but it does seem pretty robust with the clients able to connect and disconnect at will, it’ll do the job I want it for anyhow.

WPF Mini Order View

12:09 am Filed under: C#

Spent most of today refining the load builder WPF interface, after returning to the UI after few weeks, I realise I was drunk on the power of round corners and transparency at the time.

I struggled yesterday to come up with a better way to display the condensed order view, no such problem today. It all just fell together, I came up with a neat little trick to fudge a drop shadow with a single line border above or below set to black with 50% alpha.

I’m pretty happy with this part now, next I’ve got to do the same trick on the truck loads these orders go into.

WPF Mini Order View

My First Generics

11:27 pm Filed under: C#

I started laying out some code to split off the collectible objects and enemies in Ride the fury tonight, I finally found a use for a some generic types and methods.

I modified my level enemy loading code to accept any object type (what I’m calling an object type is actually an enum listing the names of the various sub types), it came together really nice and quick.

I was all set to past the code up here and decided to try and start pasting to code samples up here in a nice colured format… so then I spent the next hour (more time than it took me to write the code I wanted to past in the first place) to NOT get the CopySourceAsHtml add in to work!

So I’ve cracked the shits with it all and you don’t get to see the code… Gee I love PC’s!

Convert a String to a GUID in C#

11:01 pm Filed under: C#

This is a simple one that didn’t take all that long to find a solution for but I thought it was worth putting up here anyhow seeing it’s not all that obvious.

To convert most other data types (Strings, Ints, Chars etc) you use the Convert. system function eg.

char myChar = Convert.ToChar(myString);

char myInt = Convert.ToInt(myString);

But GUIDs are treated a little differently, you actually create a new instance seeded with the string value eg.

Guid myGuid = new Guid(myString);
« Previous Page

Powered by WordPress