zoukankan      html  css  js  c++  java
  • WP7备注(23)(Canvas改变Size|ZIndex|Canvas Touch)

    首先,Canvas有四个Attached属性:Left,Top,Right,Buttom,它们的赋值,是在子项生成的时候,以Canvas的SetXxx的形式的方法赋值上去的,所以当Canvas改变大小的时候,也要重新更新这些Attached属性:

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <Canvas Name="canvas"
    SizeChanged="OnCanvasSizeChanged" />
    </Grid>
    void OnCanvasSizeChanged(object sender, SizeChangedEventArgs args)
    {
    canvas.Children.Clear();
    for (double y = 0; y < args.NewSize.Height; y += 75)
    for (double x = 0; x < args.NewSize.Width; x += 75)
    {
    Ellipse ellipse = new Ellipse
    {
    Width = 100,
    Height = 100,
    Stroke = this.Resources["PhoneAccentBrush"] as Brush,
    StrokeThickness = 10
    };
    Canvas.SetLeft(ellipse, x);
    Canvas.SetTop(ellipse, y);
    canvas.Children.Add(ellipse);
    }
    }

    如上方代码所示

    Canvas.SetLeft(ellipse, x);

    Canvas.SetTop(ellipse, y);

    重新制定Child的位置

    同时,还有一些类似功能的代码:

    ellipse.SetValue(Canvas.LeftProperty, x);
    ellipse.SetValue(Canvas.TopProperty, y);

    double x = GetLeft(child);
    double y = GetTop(child);

    double x = (double)child.GetValue(LeftProperty);
    double y = (double)child.GetValue(TopProperty);

    ----------------------------------------------------------------------

    还有个Attached属性是ZIndex,不多解释了

    ----------------------------------------------------------------------

    protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
    {
    args.ManipulationContainer = canvas;
    base.OnManipulationStarted(args);
    }
    
    protected override void OnManipulationDelta(ManipulationDeltaEventArgs args)
    {
    UIElement element = args.OriginalSource as UIElement;
    Point translation = args.DeltaManipulation.Translation;
    Canvas.SetLeft(element, Canvas.GetLeft(element) + translation.X);
    Canvas.SetTop(element, Canvas.GetTop(element) + translation.Y);
    args.Handled = true;
    base.OnManipulationDelta(args);
    }
  • 相关阅读:
    nagios --rhel6.5
    nginx+tomcat+msm(memcached-session-manager)
    化学实验过程中对眼睛的保护
    实验室化学药品取用规则
    物理变化、化学变化、物理性质、化学性质
    windows 下在图片中隐藏文件
    老子《道德经》第六十八章
    linux 3.0.35 内核下 include/linux/compiler.h 关于__iomem
    boa 服务器进行 cgi 测试时出现 400 Bad Request 【已解决】
    linux 内核 arch 目录下处理器体系结构
  • 原文地址:https://www.cnblogs.com/otomii/p/2032618.html
Copyright © 2011-2022 走看看