2013-04-12 36 views

回答

0

如果你硬编码值,那么这样的事情会做的伎俩:

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition/> 
    </Grid.RowDefinitions> 
    <ComboBox HorizontalAlignment="Center" Margin="10"> 
     <!-- ... --> 
     <ComboBoxItem Content="10:00"/> 
     <ComboBoxItem Content="11:00"/> 
     <ComboBoxItem> 
      <ComboBoxItem.Content> 
       <Border BorderBrush="Black" BorderThickness="0,0,0,1"> 
        <TextBlock Text="12:00" Margin="0,0,0,1"/> 
       </Border> 
      </ComboBoxItem.Content> 
     </ComboBoxItem> 
     <ComboBoxItem Content="13:00"/> 
     <!-- ... --> 
    </ComboBox> 
</Grid> 
+0

感谢菲尔的回应。我忘记了我的难题是分隔符是动态的,并且可以设置它。 – OmnipresentPerception

+0

@ user1771347您是否需要更多帮助,以及动态,可见/不可见的含义? – Phil

0

我在网上找到这一招...和它的作品! 在我的XAML我已经介绍了此代码段:

<ComboBox.ItemContainerStyle> 
    <Style TargetType="{x:Type ComboBoxItem}" 
     BasedOn="{StaticResource {x:Type ComboBoxItem}}"> 
    <Style.Triggers> 
     <DataTrigger Binding="{Binding}" 
        Value=""> 
     <Setter Property="Template"> 
      <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ComboBoxItem}"> 
       <Separator HorizontalAlignment="Stretch" 
         IsEnabled="False" /> 
      </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
     </DataTrigger> 
    </Style.Triggers> 
    </Style> 
</ComboBox.ItemContainerStyle> 

然后在我后面的代码我已经insered一个全新的空白项不可编辑。 结果是预选项目下的一行。 我的目标已达成。

我希望这可能有助于某人(也是我未来:))