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);
            }
        }
    }

  • 相关阅读:
    Django: ModelForm中Meta的fields等成员介绍
    python的random函数
    设置mysql隔离级别
    ubantu 下 修改mysql 默认编码
    jdbc 模板 连接
    sql 注入 与解决
    jdbc 简单连接
    动态代理 例子
    自定义的一个数据输入类
    类加载器 读取配置文件
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434625.html
Copyright © 2011-2022 走看看