zoukankan      html  css  js  c++  java
  • WPF 绑定一(数据源为控件)

    xaml:

    <Window x:Class="WpfApplication1.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Window1" Height="321" Width="401">
        <Grid>
            <TextBox Height="23" HorizontalAlignment="Left" Margin="141,46,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Text="{Binding Path=Value,ElementName=slider1,Mode=TwoWay,UpdateSourceTrigger=LostFocus}"/>
            <Slider Height="23" HorizontalAlignment="Left" Margin="84,106,0,0" Name="slider1" VerticalAlignment="Top" Width="212" />
            <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="166,197,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        </Grid>
    </Window>

    cs:

    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.Shapes;
    
    namespace WpfApplication1
    {
        /// <summary>
        /// Window1.xaml 的交互逻辑
        /// </summary>
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
                this.textBox1.SetBinding(TextBox.TextProperty, new Binding("Value") {Source=slider1});
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                new Window2().Show();
            }
        }
    }
  • 相关阅读:
    day 03
    day 02
    day 02 作业
    day 01
    day 10 预科
    day 09作业 预科
    day 09 预科
    day 08作业 预科
    The word 'localhost' is not correctly spelled 这个问题怎么解决
    不能够连接到主机(名称为localhost)上的MySQL服务”
  • 原文地址:https://www.cnblogs.com/zwzw/p/3321057.html
Copyright © 2011-2022 走看看