سؤال

I have a RadComboBox that i have bound like shown below

<telerik1:RadComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Margin="5,2" ItemsSource="{Binding RepTypes}" DisplayMemberPath="Path=TypeName"  SelectedValuePath="Value"  SelectedItem="{Binding RepType, Mode=TwoWay}" >

                    </telerik1:RadComboBox>

When i select an Item I catch the Property Changed event, but basically the selection in the combo box stays blank.

What am i doing wrong?

Ok i made it so that it shows up now.. But i don't understand why... Or how to change it so it works for me in all cases...

           <telerik1:RadComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Margin="5,2" ItemsSource="{Binding RepTypes}" SelectedValuePath="Value"  SelectedItem="{Binding RepType, Mode=TwoWay}"  >

            </telerik1:RadComboBox>

Thats what works... the Biggest difference was. I had to name a field to "Name" and then bind it and take out the DisplayMemberPath="Path=ReportName"

If that is the case then how do i tell the control what Field to Display in the dropdown?

هل كانت مفيدة؟

المحلول

Are you somehow changing your collection? The controls only look for the items once. So, if the page loads and then you're loading your collection of RepTypes, it doesn't update the dictionary. I'm doing something similar and I'm lazy loading my collection (as you type, I get more from the database).

       <t:RadComboBox x:Name="RepTypeComboBox" Margin="0,1"
                   t:TextSearch.TextPath="TypeName"
                   ItemsSource="{Binding Path=RepTypes, Mode=OneWay}"
                   SelectedValue="{Binding Path=Reptype, Mode=TwoWay, NotifyOnValidationError=True}"                            
                   IsEditable="True" 
                   Grid.Column="1"
                   Grid.Row="2" TabIndex="1">
            <t:RadComboBox.ItemTemplate >
                <DataTemplate >
                  <StackPanel Orientation="Horizontal" >
                    <TextBlock FontWeight="Bold" Text="{Binding Path=TypeName, Mode=OneWay}" Width="75"/>
                        <TextBlock Text=": " />
                    <TextBlock Text="{Binding Path=address1, Mode=OneWay}" />
                        <TextBlock Text=" " />
                    <TextBlock Text="{Binding Path=address2, Mode=OneWay}" />
                        <TextBlock Text=" " />
                    <TextBlock Text="{Binding Path=citystate, Mode=OneWay}" />
                        <TextBlock Text=" " />
                    <TextBlock Text="{Binding Path=zip, Mode=OneWay}" />
                    </StackPanel>
                </DataTemplate>
            </t:RadComboBox.ItemTemplate>
        </t:RadComboBox>

نصائح أخرى

If you want ReportName to be shown as your display member, you only have to put it this way:

<telerik1:RadComboBox ItemsSource="{Binding RepTypes}" SelectedValuePath="Value"
SelectedItem="{Binding RepType, Mode=TwoWay}" DisplayMemberPath="ReportName">

</telerik1:RadComboBox>

You're putting an extra "Path=" that's only confusing the XAML parser.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top