0

我有以下主窗口

    <Window x:Uid="Window_1" x:Class="App1.MainWindow"  
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     
            Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded" Closing="Window_Closing" 
            SizeChanged="Window_SizeChanged" Topmost="True" AllowsTransparency="True"  Opacity="1"
            WindowStyle="None" ResizeMode="CanMinimize"  WindowStartupLocation="CenterScreen"   
            WindowState="Maximized" KeyDown="Window_KeyDown" MouseDoubleClick="Window_MouseDoubleClick"  Background="Black"
            MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseMove="Window_MouseMove"  >

 <Viewbox x:Uid="Viewbox_1" Stretch="Uniform" StretchDirection="Both" SnapsToDevicePixels="True" >
        <Grid  x:Uid="MainLayout"   Name="MainLayout" SnapsToDevicePixels="True">
            <Canvas x:Uid="MainCanvas" Name="MainCanvas" SnapsToDevicePixels="True">

            </Canvas>
        </Grid>
    </Viewbox>

但不知何故在窗口的正常模式下会出现一些填充(由于窗口背景颜色,它是黑色的)

任何线索如何取出它?

在此处输入图像描述

4

2 回答 2

2

在您的根窗口上:Background="Transparent"

于 2012-05-24T20:21:01.817 回答
1

我试图复制你的问题,但没有完整的代码,它似乎不会发生。我使用了这段代码:

<Window x:Class="WpfApplication2.MainWindow"
        x:Uid="Window_1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"      
            Title="MainWindow" Height="350" Width="525" Topmost="True" AllowsTransparency="True"  Opacity="1" 
            WindowStyle="None" ResizeMode="CanMinimize"  WindowStartupLocation="CenterScreen"  Background="Black" >


    <Grid Background="Green">
        <Viewbox x:Uid="Viewbox_1" Stretch="Uniform" StretchDirection="Both" SnapsToDevicePixels="True" >
            <Grid Background="Red"  x:Uid="MainLayout"   Name="MainLayout" SnapsToDevicePixels="True">
                <Canvas x:Uid="MainCanvas" Name="MainCanvas" SnapsToDevicePixels="True" Background="Blue">

                </Canvas>
            </Grid>
        </Viewbox>

    </Grid>
</Window>

只是想看看会发生什么。显然,没有图像,内部画布、网格和视图框不会占用任何空间,因此您得到的只是一个纯绿色窗口(主网格中的绿色与窗口的黑色完全重叠)。

我唯一的想法是:当 Viewbox 使用均匀拉伸时,它与图像的纵横比与窗口的纵横比有关吗?

于 2012-05-23T19:21:09.290 回答