将样式移动到Application.Resources时应用程序崩溃

时间:2013-08-13 17:40:41

标签: wpf wix burn

我正在为我的WiX引导程序创建一个WPF UX。

我的代码如下所示:

<Window x:Class="MyNamespace.Deployment.MainScreen"
    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"
    mc:Ignorable="d"
    WindowStyle="None" ResizeMode="NoResize" AllowsTransparency="true"
    MouseLeftButtonDown="DragWindow"
    Width="408" Height="255" >

<Window.Resources>
    <LinearGradientBrush x:Key="backgroundBrush" StartPoint=".30,.30" EndPoint=".70,.70" SpreadMethod="Reflect">
        <LinearGradientBrush.GradientStops>
            <GradientStop Offset="0" Color="#700000FF"/>
            <GradientStop Offset="1" Color="#200000FF"/>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <Style x:Key="borderStyle">
        <Setter Property="Border.Background" Value="Navy" />
        <Setter Property="Border.Margin" Value="50" />
        <Setter Property="Border.CornerRadius" Value="5" />
    </Style>
    <Style x:Key="buttonStyle">
        <Setter Property="Button.FontSize" Value="20" />
        <Setter Property="Button.Background" Value="SlateBlue" />
        <Setter Property="Button.Foreground" Value="White" />
        <Setter Property="Button.Height" Value="96" />
        <Setter Property="Button.Width" Value="96" />
        <Setter Property="Button.Margin" Value="0,0,0,0" />
        <Setter Property="Button.BorderBrush" Value="Transparent" />
    </Style>

</Window.Resources>

<Window.Background>
    <LinearGradientBrush StartPoint=".30,.30" EndPoint=".70,.70" SpreadMethod="Reflect">
        <GradientStop Offset="0" Color="#700000FF"/>
        <GradientStop Offset="1" Color="#200000FF"/>
    </LinearGradientBrush>
</Window.Background>

<Border Style="{StaticResource borderStyle}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="4"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="4"/>
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3" Text="My Thing" Style="{StaticResource titleStyle}" />
        <Button Name="buttonInstall" Grid.Row="1" Grid.Column="1" Content="Install"  Command="{Binding Path=InstallCommand}" Style="{StaticResource buttonStyle}" />
        <Button Name="buttonUninstall" Grid.Row="1" Grid.Column="2" Content="Uninstall"  Command="{Binding Path=UninstallCommand}" Style="{StaticResource buttonStyle}" />
        <Button Name="buttonExit" Grid.Row="1" Grid.Column="3" Content="{Binding Path=ExitText}"  Command="{Binding Path=ExitCommand}" Style="{StaticResource buttonStyle}" />
    </Grid>
</Border>

当我运行它时它会显示并且似乎没问题。但是,如果我将其中一个样式从Window.Resources移动到App.Resources,那么引导程序崩溃了:

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             x:Class="MyNamespace.Deployment.App" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             mc:Ignorable="d">
    <Application.Resources>
        <Style x:Key="titleStyle">
            <Setter Property="TextBlock.FontFamily" Value="Arial" />
            <Setter Property="TextBlock.FontSize" Value="20" />
            <Setter Property="TextBlock.Background" Value="Navy" />
            <Setter Property="TextBlock.Foreground" Value="White" />
            <Setter Property="TextBlock.Margin" Value="0,14,0,20" />
            <Setter Property="TextBlock.HorizontalAlignment" Value="Center" />
        </Style>
    </Application.Resources>
</Application>

BOOM!

我错过了什么?

0 个答案:

没有答案