zoukankan      html  css  js  c++  java
  • data binding

     

    <Window x:Cl

    s="databind.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" Loaded="Window_Loaded">
    <Grid>
      <StackPanel Margin="5" Name="stackPanel1" Height="310" VerticalAlignment="Bottom">
        <Slider Height="Auto" x:Name="slider1" Margin="3" Minimum="1" Maximum="40" Value="10" TickPlacement="TopLeft" TickFrequency="1" IsSnapToTickEnabled="True"/>
        <TextBlock TextWrapping="Wrap" Text="Simple Text" Margin="10" Name="TextBlock1" Foreground="{Binding ElementName=listBox1,Path=SelectedItem.Tag}"/>
        <Button Margin="5" Content="Button" Height="23" Name="button1" Width="75" Click="button1_Click"/>
        <Button Content="Cancel Binding" Height="23" VerticalAlignment="Top" Width="Auto" Click="Button2_Click"/>
        <ListBox Height="Auto" Margin="3" Name="listBox1">
          <ListBoxItem Tag="Blue">Blue</ListBoxItem>
          <ListBoxItem Tag="DarkBlue">Dark Blue</ListBoxItem>
          <ListBoxItem Tag="LightBlue">Light Blue</ListBoxItem>
        </ListBox>
        <TextBox Margin="3" Height="22" TextWrapping="Wrap" Width="120" Text="{Binding ElementName=TextBlock1,Path=FontSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
       </StackPanel>

      </Grid>
    </Window>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    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 databind
    {
      /// <summary>
      /// MainWindow.xaml 的交互逻辑
      /// </summary>
      public partial class MainWindow : Window
        {
          public MainWindow()
        {
          InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
          //this.slider1.Value = 30;
          this.TextBlock1.FontSize = 30;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
          Binding binding = new Binding();
          binding.Source = this.slider1;
          binding.Path = new PropertyPath("Value");
          binding.Mode = BindingMode.TwoWay;
          this.TextBlock1.SetBinding(TextBlock.FontSizeProperty,binding);


        }
        //删除绑定
        private void Button2_Click(object sender, RoutedEventArgs e)
        {
        BindingOperations.ClearAllBindings(this.TextBlock1);
        }
        }

        }

  • 相关阅读:
    Java学习资源整理(超级全面)
    Java中的Iterable与Iterator详解
    git使用笔记1:结合Github远程仓库管理项目
    关于LeetCode上链表题目的一些trick
    关于链表中哨兵结点问题的深入剖析
    关于Java中基类构造器的调用问题
    大整数相乘问题总结以及Java实现
    快速排序实现及其pivot的选取
    阿里云服务器部署Java Web项目全过程
    Git 学习总结
  • 原文地址:https://www.cnblogs.com/lz-huihui/p/10887729.html
Copyright © 2011-2022 走看看