WPF 重寫Window窗體的樣式為None,上方有一條白條線,如下圖:
解決方案:
Window窗體屬性設置:ResizeMode=“CanMinimize”
//
// 摘要:
// 獲取或設置調(diào)整大小模式。
//
// 返回結(jié)果:
// 一個 System.Windows.ResizeMode 值,該值指定調(diào)整大小模式。
public ResizeMode ResizeMode { get; set; }
#region 程序集 PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\PresentationFramework.dll
#endregion
namespace System.Windows
{
//
// 摘要:
// 指定是否可以調(diào)整窗口的大小,并且,如果是這樣,如何可以調(diào)整它。 使用 System.Windows.Window.ResizeMode 屬性。
[Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)]
public enum ResizeMode
{
//
// 摘要:
// 不能調(diào)整窗口的大小。 最小化 和 最大化 按鈕不顯示在標題欄中。
NoResize = 0,
//
// 摘要:
// 一個窗口僅可以最小化和還原。 最小化 和 最大化 按鈕是顯示,但僅限于 最小化 按鈕才可用。
CanMinimize = 1,
//
// 摘要:
// 可以調(diào)整窗口的大小。 最小化 和 最大化 按鈕都顯示并啟用。
CanResize = 2,
//
// 摘要:
// 可以調(diào)整窗口的大小。 最小化 和 最大化 按鈕都顯示并啟用。 大小調(diào)整手柄將顯示在窗口的右下角。
CanResizeWithGrip = 3
}
}
解決之后顯示如下:
整體代碼參考如下:文章來源:http://www.zghlxwxcb.cn/news/detail-591076.html
<Window x:Class="Solution.SpaceDemo.Window1"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Solution.SpaceDemo"
mc:Ignorable="d"
Title="Window1" Height="72" Width="881" WindowStyle="None" Background="Transparent"
ResizeMode="CanMinimize">
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<StackPanel Orientation="Horizontal" Height="72" x:Name="barWidth0" Width="425">
<Button Content="打開教材0"></Button>
<Button Content="選擇0"></Button>
<Button Content="畫筆0"></Button>
<Button Content="板擦0"></Button>
<Button Content="圈選0"></Button>
<Button Content="聚焦0"></Button>
<Button Content="學科工具0"></Button>
<Button Content="交互0"></Button>
<Button Content="錄制0"></Button>
<Button Content="本地文件0"></Button>
</StackPanel>
<ToggleButton Margin="0,0,0,0" Width="150" Height="72" Content="ToggleButton" FontSize="30">
<ToggleButton.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Checked">
<BeginStoryboard>
<Storyboard >
<DoubleAnimation Duration="0:0:2" To="0" Storyboard.TargetName="barWidth0" Storyboard.TargetProperty="Width"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="ToggleButton.Unchecked">
<BeginStoryboard>
<Storyboard >
<DoubleAnimation Duration="0:0:2" To="425" Storyboard.TargetName="barWidth0" Storyboard.TargetProperty="Width"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ToggleButton.Triggers>
</ToggleButton>
</StackPanel>
</Grid>
</Window>
備注:如果添加WindowStyle=“None” 和ResizeMode="CanMinimize"同時設置,就不會顯示橫向?qū)Ш綏l文章來源地址http://www.zghlxwxcb.cn/news/detail-591076.html
到了這里,關于WPF 設置窗體 Window的 WindowStyle=“None“ 上方有白條問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!