0

As I am new with XAML and WPF my question might be ambigious. Accept my appologies in advance.

To make it simple, I am working on a project in which I have some buttons and a custom pointer to select one of these buttons. I could get the program working without using grid rows and columns to organize my elements. However when I was maximizing the window it was a mess. So, I used grid rows and columns with persentage width and height and solved this problem. But now, the pointer gets stucked in one of the grids and does not move outside. I want to define my pointer somehow that it can move along the whole grid without getting binded to a row or column. Here is my XAML code:

<Window x:Class="testGallery.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local ="clr-namespace:Kinect.Toolbox;assembly=Kinect.Toolbox"
    Loaded="Window_Loaded"
    Title="MainWindow">

<Grid Margin="0,0,0,97">
    <Grid.RowDefinitions>
        <RowDefinition Height="68*" />
        <RowDefinition Height="101*" />
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="150*" />
        <ColumnDefinition Width="150*" />
    </Grid.ColumnDefinitions>

    <Button Click="Button_Click_1" Grid.Column="1" Grid.Row="1" Margin="10" >
        <StackPanel>
            <Image x:Name="myImage" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="5"/>
        </StackPanel>
    </Button>

    <Canvas x:Name="mouseCanvas" Margin="-24,263,24,-263"/>
</Grid>
</Window>

In the code above the Convas is my custom pointer.

4

1 回答 1

4

尝试

<Canvas x:Name="mouseCanvas" Grid.ColumnSpan="2" Grid.RowSpan="2" Margin="-24,263,24,-263"/>

这将允许您的画布使用所有可用的行和列。因为每个都有两个,所以将 Spans 设置为“2”意味着整个网格。

于 2012-09-14T16:00:04.350 回答