0

我正在尝试在一段时间内显示默认文本,ComboBox我正在从源获取数据,但它没有显示任何内容。

<ComboBox  
         Grid.Row="1" 
         Grid.Column="2" 
         Text="Hepper"
         ItemsSource="{Binding Builds}"
         SelectedItem="{Binding SelectedBuild}"
         DisplayMemberPath="VersionNo" 
         IsReadOnly="True" 
         IsEnabled="{Binding SelectedBuildEnable}" 
         VerticalAlignment="Top" 
         HorizontalAlignment="Left" 
         Width="180" 
         Height="30" 
         MinWidth="180" />
4

2 回答 2

3

您可以尝试设置ComboBox.SelectedValueProperty 而不是ComboBox.Text.

我更喜欢在 ComboBox 上方显示另一个 TextBlock 以显示默认文本:

<!-- don't forget to define the converter in your resources -->
<UserControl.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</UserControl.Resources>    

<!-- your Control -->
<ComboBox  
     Grid.Row="1" 
     Grid.Column="2" 
     x:Name="ComboBoxElement"
     ItemsSource="{Binding Builds}"
     SelectedItem="{Binding SelectedBuild}"
     DisplayMemberPath="VersionNo" 
     IsReadOnly="True" 
     IsEnabled="{Binding SelectedBuildEnable}" 
     VerticalAlignment="Top" 
     HorizontalAlignment="Left" 
     Width="180" 
     Height="30" 
     MinWidth="180" />

<TextBlock 
      Grid.Row="1" 
      Grid.Column="2" 
      Visibility="{Binding IsEnabled, ElementName=ComboBoxElement, Converter={StaticResource BooleanToVisibilityConverter}}" 
      IsHitTestVisible="False" 
      Text="Hepper" 
      VerticalAlignment="Top" 
      HorizontalAlignment="Left" 
      Margin="15,5" />

我猜想如果获取数据,您的 ComboBox 就会启用。否则,您必须使用另一个绑定来获得可见性。

于 2013-10-08T08:26:50.643 回答
0

根据 MSDN,该ComboBox.Text物业

获取或设置当前选定项的文本。

因此,您可以暂时将一个项目添加到ComboBox您所需的消息中,选择它,然后在填写ComboBox您的数据到达时间之前将其删除。

于 2013-10-08T08:13:10.870 回答