我将WPF用于使用3.5 .NET框架的Visual Studio WPF 2008项目。我是WPF的新手,特别是Expression Blend 3,我正在尝试设计用户界面。我为主窗口定义了一个漂亮的双色渐变背景。当没有菜单定义时,它可以很好地显示以下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#代码中指定,以使菜单的背景颜色仅适用于菜单而不是其他任何内容?
答案 0 :(得分:0)
很容易解决。在“布局”选项卡下的“混合3”中,存在水平对齐和垂直对齐属性。这两个都将延伸。不知道他们是怎么做到的。但是,无论如何它们应分别设置为Left和Top。这使菜单位于左上角,解决了菜单试图控制整个窗口背景颜色的问题。