zoukankan      html  css  js  c++  java
  • WPF(附加属性 Slider)

    <Window x:Class="TestOfAttachPropertyOfSlider.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Canvas >
            <Slider x:Name="sliderX" 
                    Canvas.Top="10"
                    Canvas.Left="10"
                    Width="260"
                    Minimum="50"
                    Maximum="200" />
            <Slider x:Name="sliderY"
                    Canvas.Top="40"
                    Canvas.Left="10"
                    Width="260"
                    Minimum="50"
                    Maximum="200" />
            
            <Rectangle x:Name="rect" Fill="Blue"
                       Width="30" Height="30"
                       Canvas.Left="{Binding ElementName=sliderX,Path=Value}"
                       Canvas.Top="{Binding ElementName=sliderY,Path=Value}" />
            
        </Canvas>
    </Window>
    

    ----------------------------------------------------------------------------------->

    等效的C#代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace TestOfAttachPropertyOfSlider
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                this.rect.SetBinding(Canvas.LeftProperty, new Binding("Value")
                                                              {
                                                                  Source = sliderX
                                                              });
                this.rect.SetBinding(Canvas.RightProperty, new Binding("Value")
                                                               {
                                                                   Source = sliderY
                                                               });
            }
        }
    }
    


  • 相关阅读:
    【算法笔记】B1020 月饼
    JZOJ 3412. 【NOIP2013模拟】KC看星
    JZOJ 3517. 空间航行
    JZOJ 3515. 软件公司
    JZOJ 3514. 最小比例
    JZOJ 3490. 旅游(travel)
    luogu P3178 [HAOI2015]树上操作
    JZOJ 3427. 归途与征程
    JZOJ 3426. 封印一击
    JZOJ 3425. 能量获取
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671532.html
Copyright © 2011-2022 走看看