zoukankan      html  css  js  c++  java
  • 在Silverlight里实现控件上下移动

    界面文件:
    <UserControl x:Class="SilverlightApplication1.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:DesignWidth="640" d:DesignHeight="480">
      <Grid x:Name="LayoutRoot">
       <StackPanel HorizontalAlignment="Left" Margin="48,8,0,41" Width="99" Background="Black" Name="statxt">
        <TextBox Text="TextBox1" TextWrapping="Wrap" GotFocus="TextBox_GotFocus"/>
        <TextBox Text="TextBox2" TextWrapping="Wrap" GotFocus="TextBox_GotFocus" />
        <TextBox Text="TextBox3" TextWrapping="Wrap" GotFocus="TextBox_GotFocus" />
        <TextBox Text="TextBox4" TextWrapping="Wrap" GotFocus="TextBox_GotFocus"/>
       </StackPanel>
       <Button Height="27" Margin="192,202,303,0" VerticalAlignment="Top" Content="向下移" Click="Button_Click" Tag="MoveDown"/>
       <Button Height="29" Margin="174,68,303,0" VerticalAlignment="Top" Content="向上移" Click="Button_Click" Tag="MoveUp"/>
      </Grid>
    </UserControl>
     
    后台代码:
    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 SilverlightApplication1
    {
        public partial class MainPage : UserControl
        {
            TextBox oldtxt = null;
            int oldIndex = 0;
            public MainPage()
            {
                InitializeComponent();
            }
            private void TextBox_GotFocus(object sender, RoutedEventArgs e)
            {
                oldtxt = (TextBox)sender;
                 oldIndex = statxt.Children.IndexOf(oldtxt);
            }
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                    int currentIndex = -1;
                    TextBox t = null;
                    Button btn = (Button)sender;
                    switch (btn.Tag.ToString())
                    {
                        case "MoveUp":
                            if (oldIndex > 0)
                            {
                                currentIndex = oldIndex - 1;
                                statxt.Children.RemoveAt(oldIndex);
                                statxt.Children.Insert(currentIndex, oldtxt);
                                t = (TextBox)statxt.Children[currentIndex];
                                t.Focus();
                                oldIndex = currentIndex;
                            }
                            break;
                        case "MoveDown":
                            if (oldIndex < statxt.Children.Count - 1)
                            {
                                currentIndex = oldIndex + 1;
                                t = (TextBox)statxt.Children[currentIndex];
                                statxt.Children.RemoveAt(currentIndex);
                               // statxt.Children.RemoveAt(oldIndex);
                                statxt.Children.Insert(oldIndex, t);
                                //statxt.Children.Insert(currentIndex, oldtxt);
                                t = (TextBox)statxt.Children[currentIndex];
                                t.Focus();
                                oldIndex = currentIndex;
                            }
                            break;
                    }
                    if (oldIndex == 0 || oldIndex == statxt.Children.Count - 1)
                    {
                        t = (TextBox)statxt.Children[oldIndex];
                        t.Focus();
                    }
            }
        }
    }
     

     图片显示的是:几个TextBox根据Button命令,上下移动

    作者: 风云

    出处: http://www.cnblogs.com/fengyunlishi/

    本文版权归风云和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

    作者: 风云 出处: http://www.cnblogs.com/fengyunlishi/ 本文版权归风云和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    tomcat日志警告WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
    针对数据泵导出 (expdp) 和导入 (impdp)工具性能降低问题的检查表 (文档 ID 1549185.1)
    DATAPUMP PERFORMANCE EXPDP IS VERY SLOW 10.2.0.4 TO 11.2.0.2
    oracle已知会导致错误结果的bug列表(Bug Issues Known to cause Wrong Results)
    如何进行oracle capability i/o(压力测试数据库服务器i/o性能)
    RMAN备份与恢复之删除过期备份
    DBA常用SQL之表空间与数据文件
    DBA常用SQL之会话与等待事件
    Oracle监控代理安装ITM(IBM Tivoli Monitoring)
    linux 命令之系统活动报告sar
  • 原文地址:https://www.cnblogs.com/fengyunlishi/p/2520754.html
Copyright © 2011-2022 走看看