Archive for the 'Blend' Category

WPF Binding from the CornerRadius of a Border

Ok, after posing this question over at .NET Blog it took me all of about 30 seconds to realize what I needed to do.

Is it possible to do Binding on separate corners of the CornerRadius. I would like to have a slider that the top corners on the Border increase/decrease radius as the slider is moved. But I don’t want the bottom to corners to be affected.

I had used the tutorial over at Martin Grayson: Adventures of a ‘Designer’ to create a glass button for a project I am working on. This was a great starting point for my buttons, but there were a few things I needed to modify. I am only going to show you how I was able to bind to a slider to change the radius of the button.

The first thing I did was create the control template, notice though that where the corner radius is, I have binded it to a slider that I have added. But on the one corner, the corners originally were set to 4,4,0,0, which will mean that if we use the value from the slider, it will end up looking looking distorted like Figure 1.

Distorted Buttons
Figure 1

Read more »

How to create a generic method to get selected value from WPF ListBox Control

On a recent project, I had several listbox controls and needed to pass values to a web service. Since all my listboxs used the same template, I wanted a generic method to handle the events.

Start by creating a new project named ListBoxDemo in Blend or Visual Studio. I use V# 2008 Express for my projects and prefer starting my projects there.

Add a new class file to your project and name it Contact.cs

using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;

namespace ListBoxDemo
{
    public class Contact : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void Notify(string propertyName)
        {
            if (this.PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        int pID;
        public int ID
        {
            get { return this.pID; }
            set
            {
        if (this.pID == value)
                    return;
            this.pID = value;
            Notify(”ID”);
            }
        }

        string pFirstName;
    public string FirstName
        {
            get { return this.pFirstName; }
            set
            {
                if (this.pFirstName == value)
                    return;
                this.pFirstName = value;
                Notify(”FirstName”);
            }
        }

        string pLastName;
        public string LastName
        {
            get { return this.pLastName; }
            set
            {
                if (this.pLastName == value)
                    return;
                this.pLastName = value;
                Notify(”LastName”);
            }
        }

        public string Name
        {
            get { return this.pFirstName + ” ” + this.pLastName; }
        }

        public Contact() { }

        public Contact(int Id, string FirstName, string LastName)
        {
            this.ID = Id;
            this.FirstName = FirstName;
            this.LastName = LastName;
        }
    }

    public class Contacts : ObservableCollection { }

    public class ContactsKeeper
    {
        Contacts pContacts = new Contacts();

        public Contacts Contacts
        {
            get { return pContacts; }
        }

        public ContactsKeeper()
        {
            // This will populate the control with data. You could use this
            // to load from a database or a webservice
            pContacts.Add(new Contact(1, “John”, “Smith”));
            pContacts.Add(new Contact(2, “Mike”, “Wallace”));
            pContacts.Add(new Contact(3, “Sally”, “Miller”));
            pContacts.Add(new Contact(4, “Albert”, “Einstein”));
        }
    }
}

Read more »

Outlook Navigation Pane in WPF

This is an awesome article. I have a project that I am working on and this really helped me nail down a few things.

http://dotnet.org.za/rudi/archive/2008/03/07/codeproject-article.aspx