WPF解决winform控件遮盖WPF控件问题

xiaoxiao2021-02-28  113

<Window x:Class="WpfApp1.Window2" 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/2008" xmlns:local="clr-namespace:WpfApp1" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" Title="Window2" Width="300" Height="300" mc:Ignorable="d"> <Grid> <Border Width="200" Height="200" HorizontalAlignment="Left"> <Grid> <wfi:WindowsFormsHost x:Name="mapContainer" Width="200" Height="200" Background="Purple"> <ElementHost> <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Background="Transparent"> <CheckBox Name="prtScn" Width="30" Height="30" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Background="Transparent" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"> <CheckBox.Template> <ControlTemplate TargetType="CheckBox"> <Grid> <Image Name="bg1" Opacity="1" Source="/WpfApp1;component/pbbtn1.png" /> <Image Name="bg2" Opacity="0" Source="/WpfApp1;component/pbbtn1h.png" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="true"> <Setter TargetName="bg1" Property="Opacity" Value="0" /> <Setter TargetName="bg2" Property="Opacity" Value="1" /> </Trigger> <Trigger Property="IsChecked" Value="{x:Null}"> <Setter TargetName="bg1" Property="Opacity" Value="1" /> <Setter TargetName="bg2" Property="Opacity" Value="0" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </CheckBox.Template> </CheckBox> </StackPanel> </ElementHost> </wfi:WindowsFormsHost> <wfi:WindowsFormsHost> <wf:PictureBox /> </wfi:WindowsFormsHost> </Grid> </Border> </Grid> </Window> 示例代码
转载请注明原文地址: https://www.6miu.com/read-32502.html

最新回复(0)