我正在使用http://wpfmdi.codeplex.com/库来处理我的WPF应用程序中的MDI。
我有一个包含子容器的Canvas,后者又包含许多小窗口。
我想在我的子窗口上禁用标题栏。这可能吗?我没有找到实现此目的的单个属性,特别是因为MdiChild
对象的类型为Control
而不是Window
。
这是我创建MDIChild的代码,其中包含TableWindow
类的对象。
MdiChild child = new MdiChild()
{
MaximizeBox = false,
MinimizeBox = false,
Resizable = true,
ShowIcon = false,
Content = tableWindow.Content as UIElement
};
mainContainer.Children.Add(child);
修改
答案 0 :(得分:1)
由于其为Control
,因此您必须override
其默认模板(ControlTemplate
)。
在源代码中,您将看到两个包含MdiChild控件样式的xamls - Aero.xaml
和Luna.xaml
。可以看到源代码here。只需摆脱包含按钮的StackPanel(ButtonsPanel)
和Grid(HeaderContent)
。
这就是WPF为我们提供的强大功能,您可以自定义任何控件,通过覆盖它ControlTemplate
来让它看起来像你想要的那样。
修改强>
要覆盖模板,您必须在xaml中重新定义它。您需要做的是create a style again in your Window resources, set the template for the control
,它将自动覆盖默认控件模板。只需从here复制粘贴整个模板,然后删除我上面提到的StackPanel和Grid。
<Window.Resources>
<Style TargetType="{x:Type mdi:MdiChild}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<!-- Copy paste entire template here and
just remove the StackPanel and Grid -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<强> EDIT2 强>
用此替换ControlTemplate
以禁用标题栏,但仍然为控件启用拖动操作和可调整大小的操作 -
<ControlTemplate TargetType="{x:Type mdi:MdiChild}">
<Border Name="BaseBorder" BorderThickness="1" CornerRadius="5,5,0,0"
Background="{StaticResource BackBorderBackgroundBrush}"
BorderBrush="{StaticResource BackBorderBrush}">
<Grid>
<Border Name="ContentBorder"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentControl Content="{TemplateBinding Content}" />
</Border>
<Thumb Name="DragThumb" Height="20" Margin="0,0,40,0"
VerticalAlignment="Top" Opacity="0"/>
<Rectangle Name="LeftBorder" Width="1" HorizontalAlignment="Left"
RadiusX="9" RadiusY="9"
Fill="{StaticResource NearBorderBrush}" />
<Rectangle Name="TopBorder" Height="1" VerticalAlignment="Top"
RadiusX="9" RadiusY="9"
Fill="{StaticResource NearBorderBrush}" />
<Rectangle Name="RightBorder" Width="1" HorizontalAlignment="Right"
RadiusX="9" RadiusY="9"
Fill="{StaticResource FarBorderBrush}" />
<Rectangle Name="BottomBorder" Height="1" VerticalAlignment="Bottom"
RadiusX="9" RadiusY="9"
Fill="{StaticResource FarBorderBrush}" />
<Thumb Name="ResizeLeft" Width="6" HorizontalAlignment="Left"
Margin="0,6,0,6" Opacity="0" Cursor="SizeWE"
IsHitTestVisible="{TemplateBinding Resizable}" />
<Thumb Name="ResizeTop" Height="4" VerticalAlignment="Top"
Margin="6,0,6,0" Opacity="0" Cursor="SizeNS"
IsHitTestVisible="{TemplateBinding Resizable}" />
<Thumb Name="ResizeRight" Width="6" HorizontalAlignment="Right"
Margin="0,6,0,6" Opacity="0" Cursor="SizeWE"
IsHitTestVisible="{TemplateBinding Resizable}" />
<Thumb Name="ResizeBottom" Height="6" VerticalAlignment="Bottom"
Margin="6,0,6,0" Opacity="0" Cursor="SizeNS"
IsHitTestVisible="{TemplateBinding Resizable}" />
<Thumb Name="ResizeTopLeft" Width="6" Height="6"
HorizontalAlignment="Left" VerticalAlignment="Top" Opacity="0"
Cursor="SizeNWSE"
IsHitTestVisible="{TemplateBinding Resizable}" />
<Thumb Name="ResizeTopRight" Width="6" Height="6"
HorizontalAlignment="Right" VerticalAlignment="Top"
Opacity="0" Cursor="SizeNESW"
IsHitTestVisible="{TemplateBinding Resizable}" />
<Thumb Name="ResizeBottomRight" Width="6" Height="6"
HorizontalAlignment="Right" VerticalAlignment="Bottom"
Opacity="0" Cursor="SizeNWSE"
IsHitTestVisible="{TemplateBinding Resizable}" />
<Thumb Name="ResizeBottomLeft" Width="6" Height="6"
HorizontalAlignment="Left" VerticalAlignment="Bottom"
Opacity="0" Cursor="SizeNESW"
IsHitTestVisible="{TemplateBinding Resizable}" />
</Grid>
</Border>
</ControlTemplate>