我将 WPF 用于使用 .NET 框架 3.5 的 Visual Studio WPF 2008 项目。我对 WPF 尤其是 Expression Blend 3 都是新手,我正在尝试使用它来设计用户界面。我为主窗口定义了一个漂亮的 2 色渐变背景。当没有菜单定义时,它与以下 XAML 代码一起很好地显示:
<Window
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"
x:Class="XYZZY.MainWindow"
x:Name="Window"
Title="XYZZY Lobby" HorizontalAlignment="Center"
Width="796" Height="480" mc:Ignorable="d">
<Window.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF434D7A" Offset="0"/>
<GradientStop Color="#FF180CFA" Offset="1"/>
</LinearGradientBrush>
</Window.Background>
<Grid x:Name="LayoutRoot" Width="764">
<Path Fill="Black" Stretch="Fill" Stroke="Black" HorizontalAlignment="Left" Margin="-227,0,0,184" VerticalAlignment="Bottom" Width="1" Height="1" Data="M-227,256"/>
<ListView HorizontalAlignment="Left" Width="239" Margin="0,148,0,45">
<ListView.View>
<GridView>
<GridViewColumn Width="90" Header="Game" />
<GridViewColumn Width="60" Header="Stakes" />
<GridViewColumn Width="35" Header="Seats" />
</GridView>
</ListView.View>
</ListView>
<ListView Margin="239,148,218,45">
<ListView.View>
<GridView>
<GridViewColumn Width="90" Header="Table" />
<GridViewColumn Width="15" Header="Players" />
<GridViewColumn Width="60" Header="Buy-in" />
<GridViewColumn Width="50" Header="Speed" />
<GridViewColumn Width="25" Header="H/Hr" />
<GridViewColumn Width="35" Header="Avg Pot" />
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
<ListView Margin="546,148,0,45">
<ListView.View>
<GridView>
<GridViewColumn Width="90" Header="Player" />
<GridViewColumn Width="60" Header="City" />
<GridViewColumn Width="35" Header="Chips" />
</GridView>
</ListView.View>
</ListView>
<TextBlock x:Name="LobbyServerLabel" HorizontalAlignment="Left" VerticalAlignment="Bottom" TextWrapping="Wrap" Text="Lobby Server - not connected"/>
<TextBlock x:Name="GameServerLabel" HorizontalAlignment="Center" VerticalAlignment="Bottom" TextWrapping="Wrap"><Run Text="Game Server - not connected"/></TextBlock>
<Label x:Name="SkinName1" Margin="8,54,0,0" VerticalAlignment="Top" Content="XYZZY" FontSize="36" Foreground="#FFD23C32" HorizontalAlignment="Left" FontFamily="Georgia" FontWeight="Bold"/>
<Label x:Name="SkinName2" Margin="182.405,54,459,0" VerticalAlignment="Top" Content="A A" FontSize="36" Foreground="#FFD23C32" FontFamily="Georgia" FontWeight="Bold"/>
<Image VerticalAlignment="Top" Width="41.81" Height="51.519" Source="Spade1.png" Stretch="Fill" Margin="136.595,53.384,585.595,0"/>
</Grid>
</Window>
但是,一旦我添加了一个菜单,菜单的背景颜色似乎会取代窗口其余部分的背景颜色。这是与菜单定义相同的代码:
<Window
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"
x:Class="AttackPoker2.MainWindow"
x:Name="Window"
Title="Attack Poker Lobby" HorizontalAlignment="Center"
Width="796" Height="480" mc:Ignorable="d">
<Window.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF434D7A" Offset="0"/>
<GradientStop Color="#FF180CFA" Offset="1"/>
</LinearGradientBrush>
</Window.Background>
<Grid x:Name="LayoutRoot" Width="764">
<Path Fill="Black" Stretch="Fill" Stroke="Black" HorizontalAlignment="Left" Margin="-227,0,0,184" VerticalAlignment="Bottom" Width="1" Height="1" Data="M-227,256"/>
<Menu>
<MenuItem Header="File">
<MenuItem Header="New"></MenuItem>
<MenuItem Header="Open"></MenuItem>
<MenuItem Header="Save"></MenuItem>
<Separator></Separator>
<MenuItem Header="Exit"></MenuItem>
</MenuItem>
<MenuItem Header="Edit">
<MenuItem Header="Undo"></MenuItem>
<MenuItem Header="Redo"></MenuItem>
<Separator>
<Separator.Template>
<ControlTemplate>
<Border CornerRadius="2" Padding="5" BorderBrush="Black" BorderThickness="1" Background="PaleGoldenrod">
<TextBlock FontWeight="Bold">
Editing Commands
</TextBlock>
</Border>
</ControlTemplate>
</Separator.Template>
</Separator>
<MenuItem Header="Cut"></MenuItem>
<MenuItem Header="Copy"></MenuItem>
<MenuItem Header="Paste"></MenuItem>
</MenuItem>
</Menu>
<ListView HorizontalAlignment="Left" Width="239" Margin="0,148,0,45">
<ListView.View>
<GridView>
<GridViewColumn Width="90" Header="Game" />
<GridViewColumn Width="60" Header="Stakes" />
<GridViewColumn Width="35" Header="Seats" />
</GridView>
</ListView.View>
</ListView>
<ListView Margin="239,148,218,45">
<ListView.View>
<GridView>
<GridViewColumn Width="90" Header="Table" />
<GridViewColumn Width="15" Header="Players" />
<GridViewColumn Width="60" Header="Buy-in" />
<GridViewColumn Width="50" Header="Speed" />
<GridViewColumn Width="25" Header="H/Hr" />
<GridViewColumn Width="35" Header="Avg Pot" />
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
<ListView Margin="546,148,0,45">
<ListView.View>
<GridView>
<GridViewColumn Width="90" Header="Player" />
<GridViewColumn Width="60" Header="City" />
<GridViewColumn Width="35" Header="Chips" />
</GridView>
</ListView.View>
</ListView>
<TextBlock x:Name="LobbyServerLabel" HorizontalAlignment="Left" VerticalAlignment="Bottom" TextWrapping="Wrap" Text="Lobby Server - not connected"/>
<TextBlock x:Name="GameServerLabel" HorizontalAlignment="Center" VerticalAlignment="Bottom" TextWrapping="Wrap"><Run Text="Game Server - not connected"/></TextBlock>
<Label x:Name="SkinName1" Margin="8,54,0,0" VerticalAlignment="Top" Content="Attack" FontSize="36" Foreground="#FFD23C32" HorizontalAlignment="Left" FontFamily="Georgia" FontWeight="Bold"/>
<Label x:Name="SkinName2" Margin="182.405,54,459,0" VerticalAlignment="Top" Content="Poker" FontSize="36" Foreground="#FFD23C32" FontFamily="Georgia" FontWeight="Bold"/>
<Image VerticalAlignment="Top" Width="41.81" Height="51.519" Source="Spade1.png" Stretch="Fill" Margin="136.595,53.384,585.595,0"/>
</Grid>
</Window>
我曾尝试移动菜单定义,但这无济于事。有人可以解释一下我如何在 Expression Blend 3 中指定或使用 C# 代码使菜单的背景颜色仅适用于菜单而不适用于其他任何东西吗?