zoukankan      html  css  js  c++  java
  • WPF RelativeSource的使用

    <Window x:Class="XamlTest.Window15"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Window15" Height="300" Width="300">
        <Grid>
            <StackPanel Name="sp1">
                <Grid Name="gd1">
                    <StackPanel Name="sp2">
                        <Grid Name="gd2">
                            <!--<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorLevel=1, AncestorType=StackPanel, Mode=FindAncestor}, Path=Name}"></TextBlock>-->//xaml实现
                            <TextBlock Name="txt"></TextBlock>
                        </Grid>
                    </StackPanel>
                </Grid>
            </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.Shapes;


    namespace XamlTest
    {
        /// <summary>
        /// Interaction logic for Window15.xaml
        /// </summary>
        public partial class Window15 : Window
        {
            public Window15()
            {
                InitializeComponent();
                Binding b = new Binding();
                b.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(StackPanel), 1);
                b.Path = new PropertyPath("Name");

                txt.SetBinding(TextBlock.TextProperty, b);
            }
        }
    }

  • 相关阅读:
    Linux C编程 GCC的使用
    51nod 1079 中国剩余定理
    51nod 1074 约瑟夫环 V2
    51nod 1073 约瑟夫环
    51nod 1072 威佐夫游戏
    ACM博弈论总结
    51nod 1069 Nim游戏
    2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
    2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Overlapping Rectangles
    2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Minimum Distance in a Star Graph
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434625.html
Copyright © 2011-2022 走看看