如何在WPF中的图像上制作透明画布?

时间:2012-11-26 15:53:10

标签: c# wpf xaml

我想将GameArea Canvas放在image1 Image的顶部。我试图更改ZIndex并手动将画布拖动到Image的顶部,但两者都没有工作,Canvas继续移回Image的右侧。

(对不起,如果我的英语很笨重,希望你理解我的意思)

以下是我的代码:

<Window x:Class="TugasBesarTAM_Moses_1072089.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Brickbreaker" Height="420" Width="375" Loaded="Window_Loaded"
    KeyDown="Window_KeyDown" ResizeMode="NoResize">
<DockPanel>      
    <Grid Width="350" Height="30"
          DockPanel.Dock="Top"
          ShowGridLines="True">

        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <TextBlock x:Name="txtLevel" 
                   Text="Level 00"
                   Grid.Column="0" Grid.Row="1"
                   FontSize="20" FontWeight="Medium"
                   HorizontalAlignment="Left"/>
        <TextBlock x:Name="txtScore" 
                   Text="0"
                   Grid.Column="1" Grid.Row="1"
                   FontSize="20" FontWeight="Medium"
                   HorizontalAlignment="Right"/>
    </Grid>
    <Image Height="300" Name="image1" Stretch="Fill" Width="320" Visibility="Visible" Source="/TugasBesarTAM_Moses_1072089;component/Images/Back1.jpg" Panel.ZIndex="1" />
    <Canvas x:Name="GameArea" DockPanel.Dock="Bottom" Width="320" Height="300" Panel.ZIndex="0">

    </Canvas>
</DockPanel>

感谢您的关注和帮助!

1 个答案:

答案 0 :(得分:3)

在这种情况下,Dockpanel不适合使用。改为使用网格。某事:

<Grid>
    <Image  />
    <Canvas />
</Grid>