CheckBox
CheckBox也和通常的WPF控件一样,可以定义样式和事件,同时CheckBox中可以嵌套其他控件!例子如下:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2006"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="Test.checkboxtest"
x:Name="Page"
WindowTitle="Page"
FlowDirection="LeftToRight"
Width="640" Height="480"
WindowWidth="640" WindowHeight="480" AllowDrop="False" IsEnabled="False">
<Page.Resources>
<Style x:Key="Triggers" TargetType="{x:Type CheckBox}">
<Style.Triggers>
<Trigger Property="CheckBox.IsPressed" Value="true">
<Setter Property = "Foreground" Value="Green"/>
</Trigger>
<Trigger Property="CheckBox.IsMouseOver" Value="true">
<Setter Property = "Background" Value="Red"/>
<Setter Property = "IsChecked" Value="true"/>
</Trigger>
</Style.Triggers>
</Style>
</Page.Resources>
<Grid x:Name="LayoutRoot">
<CheckBox Name="CheckBox1" HorizontalAlignment="Left" Margin="34,63,0,0"
VerticalAlignment="Top" Width="211" Height="56" Checked="HandleChange" Style="{StaticResource Triggers }">
<Image Source="images\apple.jpg" Height="43" Width="43" d:LayoutOverrides="Width, Height" HorizontalAlignment="Left" Margin="62,16,0,0" VerticalAlignment="Top"/>
</CheckBox>
</Grid>
</Page>
CS下的代码如下:
private void HandleChange(object sender, RoutedEventArgs e)
{
CheckBox1.Content = "Change Text";
}
本文参考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