zoukankan      html  css  js  c++  java
  • WPF-控件-DataTemplate生成的控件

    <Window x:Class="由DataTemplate生成的控件.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:由DataTemplate生成的控件"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <!--数据对象-->
            <local:Student x:Key="stu" Id="1" Name="张三" Skill="C#" HasJob="True"/>
            <!--DataTemplate-->
            <DataTemplate x:Key="stuDT">
                <Border BorderBrush="Orange" BorderThickness="2" CornerRadius="5">
                    <StackPanel>
                        <TextBlock Text="{Binding Id}" Margin="5"/>
                        <TextBlock x:Name="textBlockName" Text="{Binding Name}" Margin="5"/>
                        <TextBlock Text="{Binding Skill}" Margin="5"/>
                    </StackPanel>
                </Border>
            </DataTemplate>
        </Window.Resources>
        <StackPanel>
            <ContentPresenter x:Name="cp" Content="{StaticResource stu}" ContentTemplate="{StaticResource stuDT}" Margin="5"/>
            <Button Content="Find" Margin="5,0" Click="ButtonBase_OnClick"></Button>
        </StackPanel>
    </Window>
            private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
            {
                TextBlock tb = this.cp.ContentTemplate.FindName("textBlockName", this.cp) as TextBlock;
                MessageBox.Show(tb.Text);
            }
        class Student
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public string Skill { get; set; }
            public bool HasJob { get; set; }
        }
  • 相关阅读:
    leetcode 33. Search in Rotated Sorted Array
    leetcode 28. Implement strStr()
    Scala函数
    布隆过滤器相关知识
    Storm 流式计算框架
    java高并发核心类 AQS(Abstract Queued Synchronizer)抽象队列同步器
    操作系统类型&操作系统结构&现代操作系统基本特征
    Kafka笔记
    Redis shell
    Lucene笔记
  • 原文地址:https://www.cnblogs.com/chenyongblog/p/3572497.html
Copyright © 2011-2022 走看看