我搜索了整个计算器并找不到简单的解决方案来解决我的问题。WPF文本覆盖网格
我有网格,我想通过一些文字/图像覆盖整个电网。你有什么想法,我该怎么做?
其实这是俄罗斯方块游戏,我想显示用户文本/图片“游戏结束”,他失去之后,所以我需要从C#做手工。有任何想法吗 ?
感谢您的帮助:-)
<Window x:Class="TetrisWPF.MainWindow"
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"
xmlns:local="clr-namespace:TetrisWPF"
mc:Ignorable="d"
Title="MainWindow"
AllowsTransparency="True"
ResizeMode="CanResizeWithGrip"
WindowStyle="None"
ShowInTaskbar="True"
WindowState="Maximized"
KeyDown="HandleKeyDown"
Initialized="MainWindow_Initilized" Background="#222222">
<Window.Resources>
<FontFamily x:Key="FontAwesome">/Fonts/fontawesome-webfont.ttf#FontAwesome</FontFamily>
</Window.Resources>
<DockPanel LastChildFill="false">
<Button DockPanel.Dock="Right" Visibility="Hidden" Width="300">Right</Button>
<StackPanel DockPanel.Dock="Right" Width="311" >
<Button x:Name="btnPlay" Content="Play" Click="btnPlay_Click" Width="50" Height="25" Margin="5"/>
<Label Content="Score " Height="56" x:Name="Score" HorizontalAlignment="Center" FontSize="28" FontWeight="Bold" Margin="0,0,0,0"/>
<Label Content="Lines " Height="56" x:Name="Lines" HorizontalAlignment="Center" FontSize="28" FontWeight="Bold" Margin="0,0,0,0"/>
<Label Content="Level 1" Height="56" x:Name="level" HorizontalAlignment="Center" FontSize="28" FontWeight="Bold" Margin="0,0,0,0" />
<Button x:Name="buttonPlay" HorizontalAlignment="Right" VerticalAlignment="Top" Height="60" Margin="0,20,0,0" Width="205" Click="buttonPlay_Click" >
<Button.Template>
<ControlTemplate TargetType="Button">
<Image Name="img1" Source="C:\Users\xx\Pictures\btn.png" />
</ControlTemplate>
</Button.Template>
</Button>
<Button x:Name="buttonPause" Content="Pause (L1)" HorizontalAlignment="Right" VerticalAlignment="Top" Height="60" Margin="0,20,0,0" Width="205" Click="buttonPause_Click" />
<Button x:Name="buttonRestart" Content="Restart" HorizontalAlignment="Right" VerticalAlignment="Top" Height="60" Margin="0,20,0,0" Width="205" Click="buttonRestart_Click" />
<Button x:Name="buttonStop" Content="Stop" HorizontalAlignment="Right" VerticalAlignment="Top" Height="60" Margin="0,20,0,0" Width="205" Click="buttonStop_Click" />
<Button x:Name="buttonDemo" Content="Demo" HorizontalAlignment="Right" VerticalAlignment="Top" Height="60" Margin="0,20,0,0" Width="205" Click="buttonDemo_Click" />
<Button x:Name="buttonExit" Content="Exit" HorizontalAlignment="Right" VerticalAlignment="Top" Height="60" Margin="0,20,0,0" Width="205" Click="buttonExit_Click" />
<TextBlock x:Name="GameOverText" Height="56" FontSize="28" FontWeight="Bold" TextWrapping="Wrap" Text="Game Over" Foreground="#FFD41A1A"/>
<TextBlock x:Name="GamePausedText" Height="56" FontSize="28" FontWeight="Bold" TextWrapping="Wrap" Text="Game Paused" Foreground="#FF0D15B6" Margin="0,0,-0.8,0"/>
</StackPanel>
<Grid Name="MainGrid" Height="750" Width="375" DockPanel.Dock="Right">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
</DockPanel>
谢谢!你节省了我的一天,真的:-)我正在尝试类似的东西,但我不知道为什么它不起作用。你的营养很棒! – Icet
没问题。你是否试图将它添加到游戏网格中,然后在代码中添加游戏元素?这会导致订单全部搞乱(它们按您添加它们的顺序绘制)。您可以使用Canvas.ZIndex强制绘制顺序。更容易在它自己的网格中将它推向更高的树!另外,如果隐藏起来并且在需要的时候显示它们,如果它变化的很快,通常会更高效。 – Joe