0
votes

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.

1
Is the Canvas your custom pointer?Chris W.
Why do you use a Canvas for a custom pointer anyway? Couldn't you just use the Cursor property (you can find it in any control) ? I honestly think that redefining a mouse pointer is usually a bad idea for this kind of problemDamascus
I am working on a kinect based app. For it I need a custom cursor which should behave defferently, to optimize it for Kinect. And the library I am using needs to define this pointer as a convasmahsa.teimourikia

1 Answers

4
votes

Try

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

That will allow your canvas to use all your available row and columns. Because you have two of each, setting the Spans to "2" means the whole grid.