WPF:黑色区域在窗口右侧
问题描述:
当我运行该程序时,窗口右侧会出现一个大的黑色区域,我无法弄清楚原因。它在Visual Studio 2017的XAML文件页面的预览中不存在,我在Windows 7计算机上运行了一次,黑色区域不在那里(我主要在Windows 10上)。问题可能在另一个文件中,但我找不到它。也许有人有几点建议。由于WPF:黑色区域在窗口右侧
<Window x:Class="Project.Widget"
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:Project"
mc:Ignorable="d"
Title="Menu"
WindowStartupLocation="Manual"
ResizeMode="NoResize"
Width="109"
SizeToContent="WidthAndHeight"
WindowState="Minimized"
Background="#2D3A48"
Topmost="False"
Loaded="Window_Loaded"
Closing="Window_Closing" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="77"/>
<RowDefinition Height="28"/>
<RowDefinition Height="90"/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<Image x:Name="Icon"
Source="./Resources/Icon.png"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Height="77"
Width="109" />
<Label x:Name="labelUsername"
Grid.Row="1"
Content=""
FontSize="14"
Foreground="White"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center" />
<Label x:Name="labelScore"
Grid.Row="2"
Content="0%, 0 of 0"
Foreground="White"
FontSize="14"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0,0,0,0" />
<Image x:Name="AvgScoreDot"
Grid.Row="2"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Height="50"
Source=".\Resources\yellow_dot.png"
Margin="0,32,0,0"/>
<Label x:Name="labelAvgScore"
Grid.Row="2"
Content="0.0"
Foreground="White"
FontSize="24"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0,35,0,0"
FontWeight="Bold" />
<Button x:Name="MailBtn"
Grid.Row="3"
Height="60"
Width="109"
HorizontalAlignment="Center"
VerticalAlignment="Center"
BorderBrush="#FF2D3A48"
Click="Mail_Click" >
<Button.Background>
<ImageBrush
ImageSource="/Resources/mail.png"
Stretch="None" />
</Button.Background>
</Button>
<Button x:Name="MailBadgeBtn"
Grid.Row="3"
Content="0"
Foreground="White"
FontSize="11"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Height="20"
Width="20"
Margin="0,30,24,10"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Click="MailBadgeBtn_Click" BorderThickness="0">
<Button.Background>
<ImageBrush
ImageSource=".\Resources\red_dot.png" />
</Button.Background>
</Button>
<TextBlock x:Name="labelConnection"
Grid.Row="0"
Text=" No Connection or blocked by Firewall"
Foreground="Red"
Background="White"
TextWrapping="Wrap"
TextAlignment="Center"
VerticalAlignment="Center"
Height="77"
Width="109"
HorizontalAlignment="Center" />
</Grid>
答
这里就是我得到的,当我删除SizeToContent="WidthAndHeight"
并添加300的高度(我也不得不移除您的事件处理程序,因为我没有这样的代码,添加垃圾图像资源文件夹,因为我没有原始图像):
更像是你在找什么?您也可以选择将SizeToContent明确设置为“手动”。
+0
大部分是的,但是我想要在右侧或左侧没有边框,并且使宽度变小不会改变宽度 – ejderuby
哈哈,左或右?下定决心:) –
这是在右边,对不起。我会解决这个问题。但它有点固定,我甚至不知道我做了什么修复它。但是现在我遇到了这个问题,在我开始之前发生了......它集中在一个区域,它看起来像我将宽度设置得比我想要的要宽。我希望宽度与窗口顶部的图像一样宽(这是109,但宽度比那更大) – ejderuby
它一定是我在XAML之外修复它的东西。 – ejderuby