1

所以,我正在制作一个窗口打开的动画,除了一个关键部分之外,动画看起来非常适合我正在尝试做的事情......窗口所在的位置和动画中当前所在的位置之间的空间黑色的盒子。

我用谷歌搜索了很多,但我没有看到任何地方提到这个问题!

我也在标准窗口中尝试过,除了黑框仅显示在窗口边框内之外,没有其他区别。除了 Visual Studio 为我生成的任何代码之外,我的代码隐藏为零。

这是我的窗口:

<Controls:MetroWindow x:Class="Schedule.MainWindow"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="mainWindow"
    Title="MainWindow" Height="350" Width="525" WindowStartupLocation="CenterScreen">

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

<Window.RenderTransform>
    <ScaleTransform ScaleX="1" ScaleY="1" x:Name="winTransform1"/>
</Window.RenderTransform>

<Window.RenderTransformOrigin>
    <Point X=".5" Y=".5"/>
</Window.RenderTransformOrigin>

<Window.Triggers>
    <EventTrigger SourceName="mainWindow" RoutedEvent="Window.Loaded">
        <BeginStoryboard Name="openBoard">
            <Storyboard>
                <DoubleAnimation Storyboard.TargetName="winTransform1" Storyboard.TargetProperty="ScaleX"
                                 From="0" To="1" Duration="0:0:1"/>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger> 
</Window.Triggers>

<Grid> 

</Grid>

4

1 回答 1

2

您需要将 WindowsAllowsTransparency属性设置为 true,这样您就不会得到黑色背景。

Title="MainWindow" Height="350" Width="525" AllowsTransparency="True" WindowStyle="None" >

但是 AllowsTransparency仅适用于WindowStyle.None因此您将失去应用程序的默认窗口边框,我认为没有其他方法可以解决此问题,但是您可以使用关闭/最小化等按钮轻松制作自定义窗口样式

于 2013-06-01T00:52:14.817 回答