代码之家  ›  专栏  ›  技术社区  ›  jpsstavares

设置Wpf窗口样式时不显示WindowsFormsHost

  •  6
  • jpsstavares  · 技术社区  · 14 年前

    窗口Xaml:

    <Window x:Class="Telbit.TeStudio.View.Forms.FloatingTestComponentsBrowser"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        Title="Test Components Browser" Style="{DynamicResource TSHUD}"
        SizeToContent="WidthAndHeight" Closing="Window_Closing" >
    
        <Grid Name="windowContent" Height="300" Width="300">
                <WindowsFormsHost HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <wf:Button Text="Try" Name="btnTry" MaximumSize="100,25" BackColor="LightGray"/>
                </WindowsFormsHost>
        </Grid>
    </Window>
    

    <Style x:Key="TSHUD" TargetType="{x:Type Window}">
        <Setter Property="ShowInTaskbar" Value="False"/>
        <Setter Property="BorderThickness" Value="0px"/>
        <Setter Property="AllowsTransparency" Value="True"/>
        <Setter Property="WindowStyle" Value="None"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Grid x:Name="LayoutRoot">
                        <Rectangle Fill="#ED111F29" Stroke="Black" Margin="29,29,29,29" RadiusX="3" RadiusY="3" Effect="{DynamicResource TSWindowShadow}"/>
    
                        <Rectangle Name="TSHUDHeader" Stroke="Black" Margin="29,29,29,29" VerticalAlignment="Top" Height="25" RadiusX="3" RadiusY="3">
                            <Rectangle.Fill>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#ED1F3A45"/>
                                    <GradientStop Color="#EC111F29" Offset="1"/>
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
    
                        <Rectangle Name="TSHUDHeaderSplitter" Fill="#ED374551" Margin="30,54,30,29" VerticalAlignment="Top" Height="1"/>
    
                        <Label Name="TSHudTitle" Background="Transparent"
                                   Margin="41,34,41,29" Padding="0"
                                   HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="20" >
                            <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}, AncestorLevel=1}, Path=Title}"
                                       TextWrapping="Wrap" Foreground="#FF8395B1" FontWeight="Bold"/>
                        </Label>
    
                        <ContentPresenter/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    我有其他具有相同样式的窗口,但只使用WPF控件(有些使用默认样式,有些使用自定义样式),没有问题。

    Enable Visual Styles 运气不好。。

    提前谢谢你的帮助。。。

    0 回复  |  直到 13 年前
    推荐文章