C# 窗口内右侧的黑色区域
当我运行程序时,窗口右侧会出现一个很大的黑色区域,我不知道为什么。它不在Visual Studio 2017的XAML文件页面预览中,我曾在Windows 7计算机上运行过一次,但黑色区域不在那里(我主要在Windows 10上)。问题可能在另一个文件中,但我找不到它C# 窗口内右侧的黑色区域,c#,wpf,window,C#,Wpf,Window,当我运行程序时,窗口右侧会出现一个很大的黑色区域,我不知道为什么。它不在Visual Studio 2017的XAML文件页面预览中,我曾在Windows 7计算机上运行过一次,但黑色区域不在那里(我主要在Windows 10上)。问题可能在另一个文件中,但我找不到它 <Window x:Class="Project.Widget" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns
<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的高度时得到的结果(我还必须删除您的事件处理程序,因为我没有该代码,并将垃圾图像添加到Resources文件夹,因为我没有原始图像):
这更像你要找的吗?您还可以选择将SizeToContent显式设置为“手动”。lol,左还是右?下定决心:)它在右边,对不起。我会解决的。但它本身就已经修好了,我甚至不知道我做了什么来修好它。但现在我遇到了在这之前的问题。。。。它位于一个区域的中心,看起来我把宽度设置为比我想要的更宽。我希望宽度与窗口顶部的图像一样宽(它是109,但比这更宽。这一定是我在XAML之外做的某件事修复了它。大多数情况下,是的。但我希望在右侧或左侧没有边框,并且使宽度变小不会改变宽度