none
interesting Z Index behaviour

    Question

  • I've noticed zindex behaviour little different when created thru XAML vs c# code.

    I've created Canvas and added rectangle and any other UI element added after that in the XAML the other UIelement gets the mouse click and it's rendered on top of rectangle.

    contrarily in the C# i've to explicitly add Rectangle ZIndex needs to be set to -1 and hittest needs to be set to false as well. Little puzzled.

    Here's the sample XAML

    <Canvas x:Name="left" Width="600" Height="425">

    <Canvas.Clip>

      <PathGeometry x:Name="leftSheetclipPath">

      .....

      </PathGeometry>

    </Canvas.Clip>

    <Rectangle x:Name="rect" Fill="#55FF0000" Canvas.Left="0" Canvas.Top="0" Width="300" Height="995" RenderTransformOrigin="1.0,0.8">

    <Rectangle.RenderTransform>

    <RotateTransform x:Name="Angle" Angle="0"/>

    </Rectangle.RenderTransform>

    </Rectangle>

    </Canvas>

    C# approach

    rect = new Rectangle();

    rect.Width = 600;

    rect.Height = 425;

    rect.Fill =
    new SolidColorBrush(Color.FromArgb(100, 100, 50, 200));

    rect.SetValue(Canvas.LeftProperty, 0.0);

    rect.SetValue(Canvas.TopProperty, 0.0);

    rect.RenderTransformOrigin = new Point(1.0, 0.8);

    Canvas.SetZIndex(rect, -1);

    rect.IsHitTestVisible = false;

     

    Sunday, February 28, 2010 9:32 AM