要求符合条件的时候显示textblock,不符合条件的时候显示Menu,不知道怎么填了,附上一半的代码
<ComboBox Style="{StaticResource CboCommomStyle}" ItemsSource="{Binding StatusItems}" SelectedIndex="1" Margin="10,0,0,0">
<ComboBox.Resources>
<Style TargetType="MenuItem">//这句应该也是错的,不知道要填什么类型
<Style.Triggers>
<DataTrigger Binding="{Binding Path=StateType}" Value="True">
//这里本来是要显示Textblock,但是不知道要怎么写
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Resources>
<ComboBox.ItemTemplate>
<DataTemplate>
<Menu Background="Transparent">
<MenuItem Header="{Binding State}" Command="{Binding ClickedCommand}">
<MenuItem.Icon>
<Image Stretch="None" Source="{Binding Icon}" />
</MenuItem.Icon>
</MenuItem>
</Menu>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox Style="{StaticResource CboCommomStyle}" ItemsSource="{Binding StatusItems}" SelectedIndex="1" Margin="10,0,0,0">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid Name="containerGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image HorizontalAlignment="Left" Name="imgState" Stretch="None" Source="{Binding Icon}"/>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Name="txtbState" Grid.Column="1" Text="{Binding State}"/>
<Button Grid.ColumnSpan="2" Name="cmdBtn" Content="{Binding State}" Command="{Binding ClickedCommand}"
Background="Transparent" BorderBrush="Transparent" BorderThickness="0"/>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsStateType}" Value="True" >
<Setter Property="Visibility" Value="Hidden" TargetName="cmdBtn"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsStateType}" Value="False">
<Setter Property="Visibility" Value="Hidden" TargetName="imgState"/>
<Setter Property="Visibility" Value="Hidden" TargetName="txtbState"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
MenuItem?Menu呢?
有的呐,就在MenuItem上面呀……额,无语
可以在msdn上查看下属性ItemTemplateSelector或者ItemContainerStyleSelector的用法,可以实现你想要的效果