0

我正在尝试通过使用将列表框中选择的项目放入文本框,Text="{Binding ElementName=list, Path=SelectedItem.Content}"但文本框只是空白

这是 XAML:

 <TextBox x:Name="Mainwindowtext2" HorizontalAlignment="Left" Height="26" Margin="78,132,0,0" TextWrapping="Wrap" Text="{Binding ElementName=list, Path=SelectedItem.Content}" VerticalAlignment="Top" Width="133"/>
<ListBox x:Name="list" HorizontalAlignment="Left" Height="19" Margin="78,74,0,0" VerticalAlignment="Top" Width="133"  >
        <ListBoxItem Content="1"></ListBoxItem>
        <ListBoxItem Content="2"></ListBoxItem>
    </ListBox>
4

1 回答 1

0

我对您的代码进行了一些更改,这对我来说很好。

XAML
 <TextBox x:Name="Mainwindowtext2" HorizontalAlignment="Left"  Height="26" Margin="78,132,0,0" 
             Text="{Binding ElementName=list, Path=SelectedItem.Content}" Width="133"/>
    <ListBox x:Name="list" HorizontalAlignment="Left" Height="59" Margin="78,74,0,0" SelectedIndex="0"  VerticalAlignment="Top" Width="133"  >
        <ListBoxItem Content="1"></ListBoxItem>
        <ListBoxItem Content="2"></ListBoxItem>
    </ListBox>
于 2013-06-29T06:54:52.947 回答