如题!求快速解决,我新建一个窗口直接在窗口的第一个grid里放WindowsFormHost,再在里面放winform控件,这样能行!,但是我在一个窗口中布局比较复杂,容器套容器,最上层的容器里放WindowsFormHost再在里面放PictureBox就不行了 直接不显示了 !
1 <Grid Name="Rightdown" Grid.Column="1" Grid.Row="3"> 2 <Grid.ColumnDefinitions > 3 <ColumnDefinition Width="538*"></ColumnDefinition> 4 <ColumnDefinition Width="458*"></ColumnDefinition> 5 </Grid.ColumnDefinitions> 6 <WrapPanel Grid.Column="0" Background="Silver" > 7 <WindowsFormsHost Name="wfh" Height="Auto" Width="Auto" Margin="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ></WindowsFormsHost> 8 </WrapPanel> 9 <Grid Grid.Column="1" Background="Red" > 10 <WindowsFormsHost Visibility="Visible" Grid.Column="1" Height="Auto" HorizontalAlignment="Stretch" Margin="0" Name="windowsFormsHost1" VerticalAlignment="Stretch" Width="auto" > 11 <wf:PictureBox Visible="True" Name="pic1" BackColor="Black"></wf:PictureBox> 12 </WindowsFormsHost> 13 </Grid> 14 </Grid>
运行时的时候能显示就行了。
就是运行的时候不显示
汗!
@溪山行旅丶: 看看IDE中有没有异常?是不是大小为0了。
@Launcher:没有啊! 我都晕了 ,按理说不应该出现这种情况吧!
@Launcher: 你看一下我的代码有问题吗?
@溪山行旅丶: <Grid Grid.Column="1" Background="Red" >
10 <WindowsFormsHost Visibility="Visible" Grid.Column="1" Height="Auto" HorizontalAlignment="Stretch" Margin="0" Name="windowsFormsHost1" VerticalAlignment="Stretch" Width="auto" >
11 <wf:PictureBox Visible="True" Name="pic1" BackColor="Black"></wf:PictureBox>
12 </WindowsFormsHost>
13 </Grid>
你能看到这个 红色背景的框框吗?
@Launcher: 我grid的红色背景能看到,就是WindowsFormsHost看不到 我试了一下把WindowsFormsHost的背景改为黑色,视图编辑器上能看到,但是运行起来就看不到了
@溪山行旅丶: 要不我把程序发给你看一下啊!加我QQ1281224167
@溪山行旅丶: <WindowsFormsHost Visibility="Visible" Grid.Column="1" 把 Grid.Column = "1"去掉。
@Launcher: 去掉了布局就变了啊 刚刚试了一下 去掉了也不行
@Launcher: 额,看错了! 布局没变,但是还是不行
@溪山行旅丶: 你的 WindowsFormsHost 没有充满你的 <Grid Grid.Column="1" Background="Red" > ?
@Launcher:
Height="Auto" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" 我这样写的应该事充满了吧
@溪山行旅丶:
@Launcher: 我另开一个窗口这样弄也行 ,但是为什么我这个 就不行呢
@溪山行旅丶: 仔细比较源码,除了 xmal中的外,还有cs中的。
@Launcher: 我把代码全贴出来
<Window 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:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="LooksLikeThat.MainWindow" x:Name="Window" Title="MainWindow" Loaded="Window_Loaded" Width="1150" Height="700" Background="{x:Null}" AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip" Icon="/LooksLikeThat;component/Images/Title.ico"> <Window.Resources> <Style x:Key="ButtonStyle4" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="40" Height="60"> <Grid Width="40" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Left" Height="40" Margin="0" Source="Images/Import.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle5" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="40" Height="60"> <Grid Width="40" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Left" Height="40" Margin="0" Source="Images/Export.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle6" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="40" Height="60"> <Grid Width="40" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Left" Height="40" Margin="0" Source="Images/Email.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle7" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="60" Height="60" Margin="0.5,0,-22.5,0"> <Grid Width="60" HorizontalAlignment="Center" Margin="0,1,0,-1" Height="60"> <Image x:Name="image" HorizontalAlignment="Center" Height="40" Margin="0" Source="Images/Movie.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle8" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="40" Height="60"> <Grid Width="40" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Left" Height="40" Margin="0" Source="Images/Query.png" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle9" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="40" Height="60"> <Grid Width="40" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Left" Height="40" Margin="0" Source="Images/Send.png" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle10" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="50" Height="60"> <Grid Width="50" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Center" Height="40" Margin="0" Source="Images/Export.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> <Path Data="M28.875,13.625 C28.59231,9.9636844 30.468317,8.4648386 34.25,8.875 37.046751,9.4223848 38.946689,11.058769 39.875,13.875 39.748133,17.088766 38.259244,18.634683 35.5,18.625 32.941923,19.017494 32.424622,21.976846 33.25,26.625" Fill="{x:Null}" HorizontalAlignment="Right" Height="18.816" Margin="0,8.809,9.125,0" Stretch="Fill" VerticalAlignment="Top" Width="12.028" StrokeThickness="3" Stroke="#FFF59302"/> <Path Data="M32,28.25 L34.75,29.125" Fill="{x:Null}" HorizontalAlignment="Right" Margin="0,27.25,13.25,28.875" Stretch="Fill" Stroke="#FFF59302" StrokeThickness="3" Width="5.75"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle11" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="40" Height="60"> <Grid Width="40" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> <Grid x:Name="grid" Margin="0,-0.018,-0.25,20" VerticalAlignment="Top"> <Ellipse Fill="{x:Null}" Height="40" Margin="0,0.018,0.25,0" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top" Width="40"/> <Path Data="M19.5,19.75 L28.5,2.5 C22.34922,-0.79923946 16.318214,-0.91487965 10.25,2.5 z" Height="Auto" Margin="10.25,0,10.75,19.25" Stretch="Fill" Stroke="Black" StrokeThickness="0" VerticalAlignment="Stretch"> <Path.Fill> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFF5B608" Offset="1"/> <GradientStop Color="White"/> <GradientStop Color="#FFE9AC0C" Offset="0.194"/> </LinearGradientBrush> </Path.Fill> </Path> <Path Data="M19.75,20.5 L28.75,2 C35.463238,6.7955596 39.184314,12.479893 39.25,19.25 z" Fill="#FF1F1E1E" Height="Auto" Margin="19.75,2.018,0,18.5" Stretch="Fill" Stroke="Black" StrokeThickness="0" VerticalAlignment="Stretch"/> <Path Data="M19.75,20.75 L29.25,37 C36.43185,33.331956 39.707285,27.381461 39.25,19.25 z" Margin="19.75,19.268,0.958,3" Stretch="Fill" Stroke="Black" StrokeThickness="0"> <Path.Fill> <LinearGradientBrush EndPoint="0.9,0.556" StartPoint="0.049,0.117"> <GradientStop Color="#FFFBBA08" Offset="0"/> <GradientStop Color="White" Offset="1"/> <GradientStop Color="#FFFBA408" Offset="0.866"/> </LinearGradientBrush> </Path.Fill> </Path> <Path Data="M19.75,20.75 L9.75,36.25 C16.325317,40.356428 22.908441,40.625775 29.5,36.75 z" HorizontalAlignment="Stretch" Margin="9.75,0,10.75,0.5" Stretch="Fill" Stroke="Black" StrokeThickness="0" Width="Auto" Fill="Black" Height="18.75" VerticalAlignment="Bottom"/> <Path Data="M19.75,20.5 L0.25,20.75 C0.98991518,27.401843 4.0109229,32.554705 9.25,36.25 z" HorizontalAlignment="Left" Margin="0.25,0,0,3.75" Stretch="Fill" Stroke="Black" StrokeThickness="0" Width="19.5" Height="15.75" VerticalAlignment="Bottom"> <Path.Fill> <LinearGradientBrush EndPoint="0.117,0.66" StartPoint="0.986,0.052"> <GradientStop Color="#FFF79504" Offset="0"/> <GradientStop Color="White" Offset="0.929"/> <GradientStop Color="#FFFD9B0D" Offset="0.805"/> </LinearGradientBrush> </Path.Fill> </Path> <Path Data="M20,20.5 L10.5,2.5" HorizontalAlignment="Left" Height="Auto" Margin="10.5,2.518,0,19.5" Stretch="Fill" Stroke="Black" StrokeThickness="0" VerticalAlignment="Stretch" Width="9.5"> <Path.Fill> <LinearGradientBrush EndPoint="0.117,0.66" StartPoint="0.986,0.052"> <GradientStop Color="#FFF79504" Offset="0"/> <GradientStop Color="White" Offset="0.929"/> <GradientStop Color="#FFFD9B0D" Offset="0.805"/> </LinearGradientBrush> </Path.Fill> </Path> <Path Data="M0.5,21 L20.25,20.5 10.5,2.5 C3.6447115,7.2266447 0.22811368,13.462345 0.5,21 z" Height="Auto" Margin="0.485,2.518,20,19" Stretch="Fill" Stroke="Black" StrokeThickness="0" VerticalAlignment="Stretch" Fill="Black"/> </Grid> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="grid"> <Setter Property="CornerRadius" TargetName="border" Value="3"/> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle12" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="45" Height="60"> <Grid Width="45" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Center" Height="40" Margin="0" Source="Images/Meta_Data.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle13" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="40" Height="60"> <Grid Width="40" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Left" Height="40" Margin="0" Source="Images/Delete.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle14" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="40" Height="60"> <Grid Width="40" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Left" Height="40" Margin="0" Source="Images/Viewers.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle15" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="50" Height="60"> <Grid Width="50" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Center" Height="40" Margin="0" Source="Images/2DViewer.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle16" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="50" Height="60"> <Grid Width="50" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Center" Height="40" Margin="0" Source="Images/RolsKeys.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle17" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="50" Height="60"> <Grid Width="50" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Center" Height="40" Margin="0" Source="Images/4DViewer.ico" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ButtonStyle18" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="Black" BorderThickness="0" Width="50" Height="60"> <Grid Width="50" HorizontalAlignment="Center" Margin="0,0,0,-2" Height="60"> <Image x:Name="image" HorizontalAlignment="Center" Height="40" Margin="0" Source="Images/Report.png" Stretch="Fill" VerticalAlignment="Top" Width="40"/> <ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" VerticalAlignment="Bottom" Content="{TemplateBinding Content}" HorizontalAlignment="Center"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsCancel" Value="False"/> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True" SourceName="image"> <Setter Property="Background" TargetName="border"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5FD0F" Offset="1"/> <GradientStop Color="White" Offset="0"/> <GradientStop Color="#FF706D6D" Offset="0.077"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="CornerRadius" TargetName="border" Value="3"/> </Trigger> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid x:Name="LayoutRoot"> <Border BorderBrush="Black" BorderThickness="0" CornerRadius="6"> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFE5E4E4" Offset="0"/> <GradientStop Color="#FFA5A1A1" Offset="0.313"/> </LinearGradientBrush> </Border.Background> <Grid> <Grid.RowDefinitions > <RowDefinition Height="35" /> <RowDefinition Height="60"/> <RowDefinition /> <RowDefinition /> <RowDefinition Height="20"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions > <ColumnDefinition Width="130"/> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid x:Name="gridTitle" Grid.Row="0" Grid.ColumnSpan="2" MouseDown="gridTitle_MouseDown"> <Grid.ColumnDefinitions > <ColumnDefinition /> <ColumnDefinition Width="60"/> </Grid.ColumnDefinitions> <DockPanel Width="60" HorizontalAlignment="Right" Grid.Column="1" > <Button x:Name="BtnClose" Style="{StaticResource ButtonStyle1}" Width="15" Height="15" DockPanel.Dock="Right" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="2.5,0,5,0" Click="BtnClose_Click" /> <Button x:Name="BtnMax" Style="{StaticResource ButtonStyle2}" Width="15" Height="15" DockPanel.Dock="Right" Margin="2.5,0" Click="BtnMax_Click" /> <Button x:Name="BtnMin" Style="{StaticResource ButtonStyle3}" Width="15" Height="15" DockPanel.Dock="Right" VerticalAlignment="Center" HorizontalAlignment="Right" RenderTransformOrigin="-2.933,0.733" Margin="0,0,2.5,0" Click="BtnMin_Click" /> </DockPanel> <Grid Width="Auto" HorizontalAlignment="Center" VerticalAlignment="Top" Height="25" Margin="30,0,0,0" > <Image Width="25" Height="25" HorizontalAlignment="Left" Source="{Binding Icon, ElementName=Window}"/> <TextBlock Margin="30,0,0,0" Text="{Binding Title, ElementName=Window}" VerticalAlignment="Center" /> </Grid> </Grid> <Grid x:Name="gridFunctionBar" Grid.Row="1" Grid.ColumnSpan="2"> <Canvas HorizontalAlignment="Left"> <Button x:Name="BtnImport" Content="Import" Style="{DynamicResource ButtonStyle4}" FontSize="9.333" Height="60" Canvas.Left="10" d:LayoutOverrides="Height" Foreground="Black"/> <Button x:Name="BtnExport" Content="Export" Style="{DynamicResource ButtonStyle5}" FontSize="9.333" Height="60" Canvas.Left="60" d:LayoutOverrides="Height"/> <Button x:Name="BtnEmail" Content="Email" Style="{DynamicResource ButtonStyle6}" FontSize="9.333" Height="60" Canvas.Left="105" d:LayoutOverrides="Height"/> <Button x:Name="BtnMovieExport" Content="Movie Export" Style="{DynamicResource ButtonStyle7}" FontSize="9.333" Height="60" Width="40" Canvas.Left="150" d:LayoutOverrides="Height"/> <Button x:Name="BtnQuery" Content="Query" Style="{DynamicResource ButtonStyle8}" FontSize="9.333" Height="60" Canvas.Left="212" d:LayoutOverrides="Height"/> <Button x:Name="BtnSend" Content="Send" Style="{DynamicResource ButtonStyle9}" FontSize="9.333" Height="60" Canvas.Left="256" d:LayoutOverrides="Height"/> <Button x:Name="BtnAnonymize" Content="Anonymize" Style="{DynamicResource ButtonStyle10}" FontSize="9.333" Height="60" Canvas.Left="300" d:LayoutOverrides="Height"/> <Button x:Name="BtnBurn" Content="Burn" Style="{DynamicResource ButtonStyle11}" FontSize="9.333" Height="60" Canvas.Left="354" d:LayoutOverrides="Height" Foreground="Black"/> <Button x:Name="BtnMeta_Data" Content="Meta_Data" Style="{DynamicResource ButtonStyle12}" FontSize="9.333" Height="60" Canvas.Left="403" d:LayoutOverrides="Height"/> <Button x:Name="BtnDelete" Content="Delete" Style="{DynamicResource ButtonStyle13}" FontSize="9.333" Height="60" Canvas.Left="457" d:LayoutOverrides="Height"/> <Button x:Name="BtnViewers" Content="Viewers" Style="{DynamicResource ButtonStyle14}" FontSize="9.333" Height="60" RenderTransformOrigin="1.925,0.45" Canvas.Left="506" d:LayoutOverrides="Height"/> <Button x:Name="Btn2DViewer" Content="2D Viewer" Style="{DynamicResource ButtonStyle15}" FontSize="9.333" Height="60" RenderTransformOrigin="1.925,0.45" Canvas.Left="550" d:LayoutOverrides="Height"/> <Button x:Name="BtnRolsKeys" Content="Rols&Keys" Style="{DynamicResource ButtonStyle16}" FontSize="9.333" Height="60" RenderTransformOrigin="1.925,0.45" Canvas.Left="609" d:LayoutOverrides="Height"/> <Button x:Name="Btn4DViewer" Content="4D Viewer" Style="{DynamicResource ButtonStyle17}" FontSize="9.333" Height="60" RenderTransformOrigin="1.925,0.45" Canvas.Left="668" d:LayoutOverrides="Height"/> <Button x:Name="BtnReport" Content="Report" Style="{DynamicResource ButtonStyle18}" FontSize="9.333" Height="60" RenderTransformOrigin="1.925,0.45" Canvas.Left="727" d:LayoutOverrides="Height"/> </Canvas> </Grid> <Grid Name="gridLeft" Grid.Row="2" Grid.Column="0" Grid.RowSpan="2"> <Grid.RowDefinitions > <RowDefinition Height="251*"></RowDefinition> <RowDefinition Height="128*"></RowDefinition> <RowDefinition Height="165*"></RowDefinition> </Grid.RowDefinitions> <ListView Name="lvAlbums" Grid.Row="0" Style="{DynamicResource ListViewStyle1}" Tag="Albums" FontSize="10.667" FontWeight="Bold" Background="#FFCACACA"> <ListViewItem Content="Database" Style="{DynamicResource ListViewItemStyle1}"/> </ListView> <ListView Name="lvSources" Tag="Sources" Style="{DynamicResource ListViewStyle1}" Grid.Row="1" FontSize="10.667" FontWeight="Bold" Background="#FFCACACA"></ListView> <ListView Name="lvActivity" Tag="Activity" Style="{DynamicResource ListViewStyle1}" Grid.Row="2" FontSize="10.667" FontWeight="Bold" Background="#FFCACACA"></ListView> </Grid> <Grid Name="RightTop" Grid.Row="2" Grid.Column="1" > <Grid.ColumnDefinitions > <ColumnDefinition ></ColumnDefinition> <ColumnDefinition Width="200"></ColumnDefinition> </Grid.ColumnDefinitions> <DataGrid Name="dgInfo" AlternationCount="2" Grid.Column="0" FontSize="10" Background="#FFD2D2D2" BorderThickness="0" RowHeaderWidth="0" ColumnHeaderHeight="15" HorizontalGridLinesBrush="{x:Null}" Margin="0,1,0,0" AutoGenerateColumns="False" > <DataGrid.Columns> <DataGridTextColumn Width="200" Header=" ID" Binding="{Binding ID}"/> <DataGridTextColumn Width="200" Header="Birthday" Binding="{Binding Birthday}"/> <DataGridTextColumn Width="200" Header="Name" Binding="{Binding Name}"/> <DataGridTextColumn Width="*" Header="Sex" Binding="{Binding Sex}"/> </DataGrid.Columns> </DataGrid> <ListView Grid.Column="1" Style="{DynamicResource ListViewStyle1}" FontSize="10.667" FontWeight="Bold" Background="#FFFDFDFD"></ListView> </Grid> <Grid Name="Rightdown" Grid.Column="1" Grid.Row="3"> <Grid.ColumnDefinitions > <ColumnDefinition Width="538*"></ColumnDefinition> <ColumnDefinition Width="458*"></ColumnDefinition> </Grid.ColumnDefinitions> <WrapPanel Grid.Column="0" Background="Silver" > </WrapPanel> <WindowsFormsHost Width="Auto" Grid.Column="1" Background="Black" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" > <wf:PictureBox Name="pic" BackColor="Red" Width="400" Height="300"></wf:PictureBox> </WindowsFormsHost> </Grid> </Grid> </Border> </Grid> </Window>
@Launcher:
@溪山行旅丶: 把你的 Window 元素的 AllowsTransparency="True" 设置为 AllowsTransparency="False"
@溪山行旅丶: 我用 spy++ 看了下,控件的句柄是存在的,只是没有绘制出来。
@Launcher:
我窗体是不规则的啊 ,AllowsTransparency设为False就完蛋了,怎么办?
@溪山行旅丶: http://blog.csdn.net/hikaliv/article/details/5919528
你试下,有源码。不过,我想问下,你非要用 PicutureBox 吗?WPF中没有可替代的吗?
@Launcher: 哎 我也是刚刚学,wpf里面的Image和MediaElement都不怎么熟悉,而且写代码人的完全不懂WPF,悲剧
@溪山行旅丶: 个人建议你可以用 Image 来做,不会很困难的。
@Launcher: 太谢谢了!结了!
看你那个截图是有效果了,因为看到了黄色的背景,只是铺满了
遇到这种问题,一个排错的方法,是你可以先用一个简单的窗口来实验,看看是不是windowsformshost的问题。然后自己再仔细比对,看看到底哪里是不是写错了
当然,这里可以确定的是,windowsformshost里面放picturebox是没有问题的
AllowsTransparency="True" WindowsFormsHost不支持透明样式,不晓得怎么解决