silverlight 获取控件间的相对位置

silverlight 获取控件间的相对位置,第1张

概述1)前台代码 <UserControl x:Class="SilverlightApplication9.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmln

1)前台代码

<UserControl x:Class="SilverlightApplication9.MainPage"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:d="http://schemas.microsoft.com/Expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d"    d:DesignHeight="300" d:DesignWIDth="400">    <GrID x:name="LayoutRoot" Background="White">        <GrID.RowDeFinitions>            <RowDeFinition Height="50"></RowDeFinition>            <RowDeFinition Height="*"></RowDeFinition>        </GrID.RowDeFinitions>        <button name="Testbutton" WIDth="200" Height="24" Content="Add" GrID.Row="0"></button>        <ScrollVIEwer name="TestScrollVIEwer" GrID.Row="1">            <StackPanel name="TestStackPanel" OrIEntation="Vertical">            </StackPanel>        </ScrollVIEwer>    </GrID></UserControl>

2)后台代码

using System;using System.Collections.Generic;using System.linq;using System.Net;using System.windows;using System.windows.Controls;using System.windows.documents;using System.windows.input;using System.windows.Media;using System.windows.Media.Animation;using System.windows.Shapes;namespace SilverlightApplication9{    public partial class MainPage : UserControl    {        private int counter = 1;        public MainPage()        {            InitializeComponent();            Testbutton.Click += new RoutedEventHandler(Testbutton_Click);        }        voID Testbutton_Click(object sender,RoutedEventArgs e)        {            //新添加button            button button = new button();            button.WIDth = 200;            button.Height = 100;            button.Content = counter++;            button.Click += new RoutedEventHandler(button_Click);            TestStackPanel.Children.Add(button);        }        voID button_Click(object sender,RoutedEventArgs e)        {            button button = sender as button;            //获取button控件相对于StackPanel的位置            Generaltransform gt = button.transformToVisual(TestStackPanel);            Point point = gt.transform(new Point(0,0));            button.Content = "(" + point.X + "," + point.Y + ")";        }    }}
总结

以上是内存溢出为你收集整理的silverlight 获取控件间的相对位置全部内容,希望文章能够帮你解决silverlight 获取控件间的相对位置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1022912.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存