设置 Wpf 窗口样式时,WindowsFormsHost 不显示
我有一个 WPF 窗口,里面有一个 WinForms 按钮。当我设置窗口样式时,按钮不会呈现,但是当未设置窗口样式时,按钮会按应有的方式显示。
窗口 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 控件(有些具有默认样式,有些具有自定义样式),没有问题。
我尝试启用视觉样式但没有成功..
谢谢提前寻求任何帮助...
I have a WPF Window that has a WinForms Button inside. When I set the Style of the Window the button isn't rendered, but when the Window Style is not set the Button appears as it should be.
Window 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>
Here is the Style for the 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>
I have other windows with the same style but only with WPF controls (some with default style and some with custom style) and there is no problem.
I've tried to Enable Visual Styles with no luck..
Thanks in advance for any help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论