【发布时间】:2019-07-13 21:19:58
【问题描述】:
我正在尝试在 WPF 中创建一个自定义弹出窗口,但如果没有围绕它的黑色“投影”,我似乎无法做到这一点。我使用 ContentControl 作为它的主体,以便我可以为不同的弹出窗口更改主体。
我可以通过删除 SizeToContent="WidthAndHeight" 来删除“阴影”,但是我没有一个窗口可以适应它的内容。
这是 xaml
<Window x:Class="PriceFinding.Utility.Dialogs.Service.DialogWindow"
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PriceFinding.Utility.Dialogs.Service"
mc:Ignorable="d"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterScreen"
MinHeight="300" MinWidth="800"
Background="{StaticResource BrushPrimary}"
>
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="50"/>
</WindowChrome.WindowChrome>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" WindowChrome.IsHitTestVisibleInChrome="True" VerticalAlignment="Top" Background="{StaticResource BrushPrimaryDark}" Name="TitleBar" Height="35">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Image Source = "pf.ico" Height="20" Width="20" Margin="5,0" />
<Label Content="{Binding Title}" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="14"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,5,0">
<Button
x:Name="MinButton"
Height="35" Width="35" Padding="0"
Command="{Binding MinimizeButton.MinimizeCommand}">
</Button>
<Button
x:Name="MaxButton"
Height="35" Width="35" Padding="0"
HorizontalAlignment="Left"
Command="{Binding MaximizeButton.MaximizeCommand}">
</Button>
<Button
x:Name="CloseButton"
Height="35" Width="35" Padding="0"
HorizontalAlignment="Right"
Command="{Binding CloseButton.CloseCommand}">
</Button>
</StackPanel>
</Grid>
<ContentControl Grid.Row="1" x:Name="ContentPresenter" Content="{Binding}"></ContentControl>
</Grid>
我该如何解决这个问题?
【问题讨论】:
-
您的应用主窗口是否也有阴影?也许它是 Windows 8/10 的东西?否则,您可以使用 MahApps Metro 之类的东西并禁用阴影属性
-
@MickyD 我不认为这是一个真正的影子。它似乎是弹出窗口的一部分,但由于某种原因画错了。我可以通过拖动黑色部分的边缘来调整弹出窗口的大小,就像我可以通过拖动另一侧来调整大小一样。同样,只需将大小调整一毫米,“阴影”就会消失,弹出窗口看起来应该如此。
-
你有没有想过这个问题?