Click here to Skip to main content
15,442,338 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: SplitContainer in WPF ? [modified] Pin
Weifen Luo10-Jul-09 13:28
MemberWeifen Luo10-Jul-09 13:28 
Questionsount control slider Pin
yogesh_softworld12320-Apr-09 8:11
Memberyogesh_softworld12320-Apr-09 8:11 
AnswerRe: sount control slider Pin
BlitzPackage22-Apr-09 5:33
MemberBlitzPackage22-Apr-09 5:33 
AnswerRe: sount control slider Pin
sivaddrahcir24-Apr-09 12:58
Membersivaddrahcir24-Apr-09 12:58 
QuestionChat application in wpf using TCp/IP Pin
JS 200820-Apr-09 5:22
MemberJS 200820-Apr-09 5:22 
AnswerRe: Chat application in wpf using TCp/IP Pin
Ray Cassick20-Apr-09 5:42
MemberRay Cassick20-Apr-09 5:42 
GeneralRe: Chat application in wpf using TCp/IP Pin
JS 200820-Apr-09 17:48
MemberJS 200820-Apr-09 17:48 
QuestionWPF ComboBox Pin
mark_w_20-Apr-09 5:02
Membermark_w_20-Apr-09 5:02 
Good afternoon.

I cant seem to get a combobox to select a value using Binding. I have a small example that re-creates the issue, I want the combo to have selected Yellow (_colour is set to that on creation) when it first loads. Hope that makes sense

Code is below, just window1 and a class called ViewModel. TIA for any help Smile | :)

Window1.xaml

<window x:class="ComboBoxTest.Window1" xmlns:x="#unknown">
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <grid>
        <combobox margin="92,122,66,116">
                    ItemsSource="{Binding Path=Colours}"
                    DisplayMemberPath="Description"
                    SelectedItem="{Binding Path=SelectedColour, Mode=TwoWay}"
                    Grid.Column="1" 
                    Grid.Row="8" 
                    IsSynchronizedWithCurrentItem="True" 
                  
                  
                  />
    </combobox></grid>
</window>


Window1.xaml.cs

using System.Windows;

namespace ComboBoxTest
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            this.DataContext = new ViewModel();
            InitializeComponent();
        }
    }
}




ViewModel.cs

using System;
using System.Collections.Generic;
using System.Windows;

namespace ComboBoxTest
{

    public class Colour : IComparable
    {
        public string Description { get; set; }

        #region IComparable Members

        public int CompareTo(object obj)
        {
            return string.Compare(((Colour) obj).Description, this.Description);
        }

        #endregion
    }

    public class ViewModel : DependencyObject
    {
        public List<colour> Colours
        {
            get
            {
                List<colour> retval = new List<colour>();
                retval.Add(new Colour { Description = "Blue" });
                retval.Add(new Colour { Description = "Green" });
                retval.Add(new Colour { Description = "White" });
                retval.Add(new Colour { Description = "Yellow" });
                retval.Add(new Colour { Description = "Red" });
                retval.Add(new Colour { Description = "Silver" });
           

                return retval;
            }
        }

        private Colour _colour = new Colour { Description = "Yellow" };

        public Colour SelectedColour
        {
            get { return _colour; }
            set { _colour = value; }

        }
        public static readonly DependencyProperty SelectedColourProperty =
            DependencyProperty.Register("SelectedColour", typeof(Colour), typeof(ViewModel));



    }
}

AnswerRe: WPF ComboBox Pin
Insincere Dave20-Apr-09 16:30
MemberInsincere Dave20-Apr-09 16:30 
GeneralRe: WPF ComboBox Pin
mark_w_20-Apr-09 22:11
Membermark_w_20-Apr-09 22:11 
GeneralRe: WPF ComboBox Pin
mark_w_21-Apr-09 0:08
Membermark_w_21-Apr-09 0:08 
AnswerRe: WPF ComboBox Pin
Mark Salsbery21-Apr-09 6:13
MemberMark Salsbery21-Apr-09 6:13 
GeneralRe: WPF ComboBox Pin
mark_w_21-Apr-09 22:33
Membermark_w_21-Apr-09 22:33 
QuestionAnalog CLock in WPF Pin
kiemchung20-Apr-09 0:57
Memberkiemchung20-Apr-09 0:57 
AnswerRe: Analog CLock in WPF Pin
Pete O'Hanlon20-Apr-09 1:32
mvaPete O'Hanlon20-Apr-09 1:32 
QuestionThrowing videos using Silverlight Pin
pavanip19-Apr-09 20:24
Memberpavanip19-Apr-09 20:24 
AnswerRe: Throwing videos using Silverlight Pin
Michael Sync23-Jul-09 20:47
MemberMichael Sync23-Jul-09 20:47 
QuestionCFormView in WPF Pin
Member 377636719-Apr-09 18:13
MemberMember 377636719-Apr-09 18:13 
AnswerRe: CFormView in WPF Pin
Pete O'Hanlon19-Apr-09 21:52
mvaPete O'Hanlon19-Apr-09 21:52 
QuestionPerformance - Memory Usage Pin
Jammer19-Apr-09 9:24
MemberJammer19-Apr-09 9:24 
AnswerRe: Performance - Memory Usage Pin
Roman Lerman20-Apr-09 22:14
MemberRoman Lerman20-Apr-09 22:14 
GeneralRe: Performance - Memory Usage Pin
Jammer21-Apr-09 8:26
MemberJammer21-Apr-09 8:26 
QuestionDatabinding in UserControl [modified] Pin
mikla52119-Apr-09 6:43
Membermikla52119-Apr-09 6:43 
AnswerRe: Databinding in UserControl Pin
Mark Salsbery19-Apr-09 7:44
MemberMark Salsbery19-Apr-09 7:44 
GeneralRe: Databinding in UserControl Pin
mikla52119-Apr-09 18:38
Membermikla52119-Apr-09 18:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.