ComboBox
XAML代码
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Test.combox1"
x:Name="Page"
WindowTitle="Page"
FlowDirection="LeftToRight"
Width="640" Height="480"
WindowWidth="640" WindowHeight="480">
<Page.Resources>
<Style x:Key="Triggers" TargetType="{x:Type ComboBoxItem}">
<Style.Triggers>
<Trigger Property="ComboBoxItem.IsMouseOver" Value="true">
<Setter Property = "Foreground" Value="Red"/>
<Setter Property = "FontSize" Value="18"/>
<Setter Property = "FontFamily" Value="Arial Bold"/>
</Trigger>
</Style.Triggers>
</Style>
</Page.Resources>
<Grid x:Name="LayoutRoot">
<ComboBox Text="Is not open" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left" Margin="44,0,0,0" VerticalAlignment="Top" Width="215" Height="25">
<ComboBoxItem Style="{StaticResource Triggers}" MouseMove="OnHover" Name="cbi1">Item1</ComboBoxItem>
<ComboBoxItem Style="{StaticResource Triggers}" MouseMove="OnHover" Name="cbi2">Item2</ComboBoxItem>
<ComboBoxItem Style="{StaticResource Triggers}" MouseMove="OnHover" Name="cbi3">Item3</ComboBoxItem>
</ComboBox>
<ComboBox Name="cb" Margin="44,151,0,225" HorizontalAlignment="Left" Width="200">
<ComboBoxItem Style="{StaticResource Triggers}">
<ComboBoxItem Style="{StaticResource Triggers}">
<Image Source="images\apple.jpg" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="114.667" Height="86"/>
</ComboBoxItem >
<ComboBoxItem Style="{StaticResource Triggers}">
<Button HorizontalAlignment="Left" Click="OnClick" Margin="0,0,0,0" VerticalAlignment="Top" Width="87" Height="20" Content="Button"/>
</ComboBoxItem>
<ComboBoxItem Style="{StaticResource Triggers}">
<TextBox Name="text" Margin="0,0,0,0" VerticalAlignment="Top" Height="24" Text="TextBox" TextWrapping="Wrap"/>
</ComboBoxItem>
</ComboBox>
</Grid>
</Page>
CS代码:
private void OnHover(object sender, RoutedEventArgs e)
{
cbi1.Content = "You clicked the check box";
}
private void OnClick(object sender, RoutedEventArgs e)
{
text.Text = "GSW";
}
第一个ComboBox的效果
第二个ComboBox的效果。
本文参考MSDN组织。
《asp.net core精要讲解》 https://ke.qq.com/course/265696
《asp.net core 3.0》 https://ke.qq.com/course/437517
《asp.net core项目实战》 https://ke.qq.com/course/291868
《基于.net core微服务》 https://ke.qq.com/course/299524