2012-02-12 125 views
0

当我选择下面组合框的任何项目时,它不显示在组合框上。即使其项目列表已填充并允许选择其项目,组合框始终为空白。wpf组合框的选定值不显示在组合框上

我看了起来,它看起来像我到目前为止所做的一切都是它应该的方式,但显然有些事情是错误的!

<ComboBox Margin="0,61,32,0" Width="100" Height="26" HorizontalAlignment="Right" x:Name="ExportComboBox"> 
        <ComboBoxItem Width="100"> 
         <StackPanel Orientation="Horizontal"> 
          <Image Height="24" Source="Images/Word.png" Width="24" ToolTip="Word - .doc" /> 
          <TextBlock Text=" Word" /> 
         </StackPanel> 
        </ComboBoxItem> 
        <ComboBoxItem Width="100"> 
         <StackPanel Orientation="Horizontal"> 
          <Image Height="24" Source="Images/Excel.png" Width="24" ToolTip="Excel - .xls"/> 
          <TextBlock Text=" Excel" /> 
         </StackPanel> 
        </ComboBoxItem> 
        <ComboBoxItem Width="100"> 
         <StackPanel Orientation="Horizontal"> 
          <Image Height="24" Source="Images/Txt.png" Width="24" ToolTip="Text - .txt" /> 
          <TextBlock Text=" Text File" /> 
         </StackPanel> 
        </ComboBoxItem> 
       </ComboBox> 

任何帮助将十分赞赏, ř

回答

2

设置在加载组合框时,将选择的组合框为0并且所述第一值的SelectedIndex属性。

<ComboBox SelectedIndex="0" Margin="0,61,32,0" Width="100" Height="26" HorizontalAlignment="Right" x:Name="ExportComboBox"> 
+0

问题是,当我从组合框中选择任何值时,选定的值以后不会显示在组合框中。 – Reda 2012-02-13 12:00:39

+0

嗯,这很奇怪,我不知道为什么会这样,除非你有一个覆盖ComboBox模板的样式。我已经复制了你的代码,它对我来说工作正常,使用VS 2010的3.5和4.0 – Terkel 2012-02-13 14:15:56