zoukankan      html  css  js  c++  java
  • WPF(Binding of RelativeSource)

    <Window x:Class="TestOfRelativeSource.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="350" Width="525">
        <Grid x:Name="g1" Background="Red" Margin="10">
            <DockPanel x:Name="d1" Background="Orange"
                       Margin="10" >
                <Grid x:Name="g2" Background="Yellow"
                      Margin="10" >
                    <DockPanel x:Name="d2" Background="LawnGreen" 
                               Margin="10" >
                        <TextBox x:Name="textBox1" 
                                 FontSize="24" Margin="10" />
                    </DockPanel>
                </Grid>
            </DockPanel>
             
        </Grid>
    </Window>
    
    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 TestOfRelativeSource
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                //RelativeSource rs = new RelativeSource(RelativeSourceMode.FindAncestor);
                //rs.AncestorLevel = 1;
                //rs.AncestorType = typeof (Grid);
                //Binding binding = new Binding("Name")
                //{
                //    RelativeSource = rs
                //};
                //this.textBox1.SetBinding(TextBox.TextProperty, binding);
    
                //RelativeSource rs = new RelativeSource();
                //rs.AncestorLevel = 2;
                //rs.AncestorType = typeof (DockPanel);
                //Binding binding = new Binding("Name")
                //{
                //    RelativeSource = rs
                //};
                //this.textBox1.SetBinding(TextBox.TextProperty, binding);
    
                this.textBox1.SetBinding(TextBox.TextProperty, new Binding("Name")
                            {
                                RelativeSource = new RelativeSource()
                                                    {
                                                        Mode = RelativeSourceMode.Self
                                                    }
                            });
            }
        }
    }
    


  • 相关阅读:
    HDU 5835 Danganronpa(弹丸论破)
    HDU 5813 Elegant Construction(优雅建造)
    HDU 5831 Rikka with Parenthesis II(六花与括号II)
    HDU 5810 Balls and Boxes(盒子与球)
    HDU 5818 Joint Stacks(联合栈)
    Dream Team(最小生成树)
    带权并查集
    HDU 1495 非常可乐(BFS)
    I Hate It(线段树+更新)
    Just a Hook(线段树+区间更新)
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671538.html
Copyright © 2011-2022 走看看