2017-06-15 104 views
0

當我運行該程序時,窗口右側會出現一個大的黑色區域,我無法弄清楚原因。它在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> 

Here's an image of what I get when I run it

+0

哈哈,左或右?下定決心:) –

+0

這是在右邊,對不起。我會解決這個問題。但它有點固定,我甚至不知道我做了什麼修復它。但是現在我遇到了這個問題,在我開始之前發生了......它集中在一個區域,它看起來像我將寬度設置得比我想要的要寬。我希望寬度與窗口頂部的圖像一樣寬(這是109,但寬度比那更大) – ejderuby

+0

它一定是我在XAML之外修復它的東西。 – ejderuby

回答

0

這裏就是我得到的,當我刪除SizeToContent="WidthAndHeight"並添加300的高度(我也不得不移除您的事件處理程序,因爲我沒有這樣的代碼,添加垃圾圖像資源文件夾,因爲我沒有原始圖像):

enter image description here

更像是你在找什麼?您也可以選擇將SizeToContent明確設置爲「手動」。

+0

大部分是的,但是我想要在右側或左側沒有邊框,並且使寬度變小不會改變寬度 – ejderuby