Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Binding a ComboBox
Message
De
02/04/2009 18:58:53
Sid Meyers
Omegaware Consulting, Inc.
Minnesota, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Titre:
Binding a ComboBox
Versions des environnements
Environment:
C# 3.0
OS:
Vista
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01392887
Message ID:
01392887
Vues:
91
OK, another hurdle to jump!

I'm trying to build a window of customer phone #'s with a combobox of phone type. I can semi get this working but not 100%.

What I want is a Listview of the phone #'s and a combobox next to each to specify it's type. I've created a DataTemplate for the Listview but when I try and hookup the binding for the combobox back to the PhoneTypes I can't get it to display.

Here's what I've got working so far:

In the Window_Loaded event - (I'm using MereMortals 3.5 Business Objects)
            this.cboPhoneTypes.ItemsSource =  this.PhoneTypes.GetAllEntities();
This will work if I have the XAML as follows:
                        <ComboBox Grid.Row="1" x:Name="cboPhoneTypes"
                          DisplayMemberPath="PhoneType"
                          SelectedValuePath="PhoneTypeID"
                          SelectedItem="{Binding Path=PhoneTypeID}"
                           />

                        <ListView Grid.Row="2" x:Name="lstChurchPhones" ItemTemplate="{DynamicResource PhoneTemplate}" >
                        </ListView>
The ComboBox is not wired up to the actual data record but it will at least display the PhoneType options, although I've noticed if I have the ItemsSource specified in XAML it doesn't work, only if I've got it specified in the code behind.

If I move the ComboBox construct into my PhoneTemplate I no longer get any of the PhoneType options, here's the code:
        <DataTemplate x:Key="PhoneTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                
                <scs:scsDataEntryTextBox x:Name="txtPhoneNumber" Text="{Binding Path=PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=Explicit}"/>
                <ComboBox Grid.Column="1" x:Name="cboPhoneTypes"
                          ItemsSource="{Binding Source=ListPhoneTypes}"
                          DisplayMemberPath="PhoneType"
                          SelectedValuePath="PhoneTypeID"
                          SelectedItem="{Binding Path=PhoneTypeID}"
                          />
            </Grid>
        </DataTemplate>
Obviously I'm missing something in my ItemsSource binding but I can't seem to figure it out. Any help would be greatly appreciated!

Thanks,
-Sid Meyers
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform