Click here to Skip to main content
16,005,080 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Want to learn Silverlight from scratch in ASP.Net Pin
Abhinav S11-Jul-10 23:08
Abhinav S11-Jul-10 23:08 
AnswerRe: Want to learn Silverlight from scratch in ASP.Net Pin
Kunal Chowdhury «IN»12-Jul-10 17:23
professionalKunal Chowdhury «IN»12-Jul-10 17:23 
QuestionComboBox Items (Binding?) Pin
seblake11-Jul-10 13:31
seblake11-Jul-10 13:31 
AnswerRe: ComboBox Items (Binding?) Pin
Jammer11-Jul-10 22:43
Jammer11-Jul-10 22:43 
GeneralRe: ComboBox Items (Binding?) Pin
seblake13-Jul-10 16:58
seblake13-Jul-10 16:58 
GeneralRe: ComboBox Items (Binding?) Pin
Jammer14-Jul-10 1:36
Jammer14-Jul-10 1:36 
GeneralRe: ComboBox Items (Binding?) Pin
seblake14-Jul-10 8:03
seblake14-Jul-10 8:03 
GeneralRe: ComboBox Items (Binding?) Pin
Jammer14-Jul-10 23:37
Jammer14-Jul-10 23:37 
Start a new project then paste this in:

MainWindow.xaml

<Window x:Class="ComboBoxDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        DataContext="{Binding RelativeSource={RelativeSource self}}"
        Title="MainWindow"
        Height="350" 
        Width="525">
    
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="40" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <ComboBox ItemsSource="{Binding MyData}" 
                  DisplayMemberPath="Value1" 
                  SelectedItem="{Binding YourSelectedItem}" Grid.ColumnSpan="3" />

        <TextBox Text="{Binding YourSelectedItem.Value1}" Grid.Row="1" />
        <TextBox Text="{Binding YourSelectedItem.Value2}" Grid.Row="1" Grid.Column="1" />
        <TextBox Text="{Binding YourSelectedItem.Value3}" Grid.Row="1" Grid.Column="2" />
    </Grid>
</Window>


Code Behind:

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

namespace ComboBoxDemo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : INotifyPropertyChanged
    {
        public ObservableCollection<MyDataObject> MyData { get; set; }

        private MyDataObject yourSelectedItem;
        public MyDataObject YourSelectedItem
        {
            get { return yourSelectedItem; }
            set { yourSelectedItem = value; OnPropertyChanged("YourSelectedItem"); }
        }

        public MainWindow()
        {
            MyData = new ObservableCollection<MyDataObject>();

            InitializeComponent();

            AddData(new MyDataObject {Value1 = 1, Value2 = "string 1", Value3 = 1});
            AddData(new MyDataObject {Value1 = 2, Value2 = "string 2", Value3 = 2});
            AddData(new MyDataObject {Value1 = 3, Value2 = "string 3", Value3 = 3});
        }

        public void AddData(MyDataObject obj)
        {
            MyData.Add(obj);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string info)
        {
            if(PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
}


MyDataObject:

namespace ComboBoxDemo
{
    public class MyDataObject
    {
        public int Value1 { get; set; }
        public string Value2 { get; set; }
        public int Value3 { get; set; }
    }
}


QuestionToggleButton in datagrid Pin
Chris Hotchkiss11-Jul-10 6:28
Chris Hotchkiss11-Jul-10 6:28 
AnswerRe: ToggleButton in datagrid Pin
Jammer11-Jul-10 22:47
Jammer11-Jul-10 22:47 
AnswerRe: ToggleButton in datagrid Pin
sillvor12-Jul-10 11:56
sillvor12-Jul-10 11:56 
QuestionTab index not working properly with user controls Pin
dashingsidds10-Jul-10 2:37
dashingsidds10-Jul-10 2:37 
QuestionNo connection could be made because the target machine actively refused it Pin
Venkadeshbabu9-Jul-10 2:08
Venkadeshbabu9-Jul-10 2:08 
AnswerRe: No connection could be made because the target machine actively refused it Pin
Pete O'Hanlon9-Jul-10 2:34
mvePete O'Hanlon9-Jul-10 2:34 
AnswerRe: File Upload in Silver Light Pin
Abhinav S9-Jul-10 17:47
Abhinav S9-Jul-10 17:47 
QuestionWorking Out Which Controls are Within Points Pin
Jammer9-Jul-10 0:23
Jammer9-Jul-10 0:23 
AnswerRe: Working Out Which Controls are Within Points Pin
Pete O'Hanlon9-Jul-10 1:54
mvePete O'Hanlon9-Jul-10 1:54 
GeneralRe: Working Out Which Controls are Within Points Pin
Jammer9-Jul-10 2:39
Jammer9-Jul-10 2:39 
GeneralRe: Working Out Which Controls are Within Points Pin
Jammer9-Jul-10 3:37
Jammer9-Jul-10 3:37 
GeneralRe: Working Out Which Controls are Within Points Pin
Pete O'Hanlon9-Jul-10 3:50
mvePete O'Hanlon9-Jul-10 3:50 
QuestionWPF Navigation Frame Pin
Gretna7-Jul-10 22:55
Gretna7-Jul-10 22:55 
QuestionWPF : Print Page number on footer Pin
priyagee7-Jul-10 21:30
priyagee7-Jul-10 21:30 
QuestionSimple problem pre-select WPF Codeplex ComboBox item [modified] Pin
devvvy7-Jul-10 15:54
devvvy7-Jul-10 15:54 
Questionmultiple WCF client endpoints exposed as dropdown list Pin
Michael Eber7-Jul-10 13:00
Michael Eber7-Jul-10 13:00 
QuestionDomainServicess??? Pin
Chris H Developer7-Jul-10 8:32
Chris H Developer7-Jul-10 8:32 

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.