문제

I created the following list

List<cb> combolist = new List<cb>();

combolist.Add(new cb() { name = "Neo",bloodgroup = "O+ve"}); 

combolist.Add(new cb() { name = "meo", bloodgroup = "O" });

combolist.Add(new cb() { name = "bsv", bloodgroup = "B+ve" });

cboxnames.ItemsSource = combolist;

Now I am creating a combobox that gets data from the above list using Item template

<ComboBox Margin="12,31,421,258" Name="cboxnames" IsEditable="False">
  <ComboBox.ItemTemplate>
     <DataTemplate>
             <TextBlock Text="{Binding name}"/>
         </DataTemplate>
        </ComboBox.ItemTemplate>   
</ComboBox>

Now I am creating an additional textblock that displays the item that is selected in the combobox

<TextBlock Height="28" HorizontalAlignment="Left" Background="LightGray" Margin="0,138,0,0" Text="{Binding UpdateSourceTrigger=PropertyChanged,ElementName=cboxnames,Mode=TwoWay,Path=SelectedItem.Content}" VerticalAlignment="Top" Width="191" />

The problem is whenever I am selecting an item from combobox, that item is not displayed in the textblock, please help!!!

도움이 되었습니까?

해결책

<TextBlock Text="{Binding UpdateSourceTrigger=PropertyChanged,
                          ElementName=cboxnames,
                          Mode=TwoWay,Path=SelectedItem.name}"/>

use this..hope it helps you

다른 팁

Hi Check your TextBlock Binding . It should be SelectedItem.name instead of SelectedItem.Content

Text="{Binding UpdateSourceTrigger=PropertyChanged,ElementName=cboxnames,Mode=TwoWay,Path=**SelectedItem.name**}" 

I hope this will help.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top