陋室铭
永远也不要停下学习的脚步(大道至简至易)

posts - 2169,comments - 570,views - 413万

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<DataGrid Name="DataGrid1" HorizontalAlignment="Left" Height="200" Margin="69,200,0,0" VerticalAlignment="Top" Width="500" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTextColumn Header="序号"  Binding="{Binding Value1}"></DataGridTextColumn>
        <DataGridTextColumn Header="值"  Binding="{Binding Value2}"></DataGridTextColumn>
        <DataGridTemplateColumn Header="操作状态" Width="120*">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
                        <Label Name="Label1" Content="Label"/>
                        <Button Content="开始下载" Name="Bianji" Tag="{Binding Value1}" Click="Button1_Click" />
                        <Button Content="停止下载" Name="Shangchu" Tag="{Binding Value1}" Click="Button2_Click" Foreground="#FFE01919" />
                    </StackPanel>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

 

1
2
3
4
5
6
7
8
9
10
11
private void Button1_Click(object sender, RoutedEventArgs e)
{
    Button b = (Button)sender;
    int index = DataGrid1.SelectedIndex;
    object ww = DataGrid1.SelectedItem;
 
    StackPanel sp = b.Parent as StackPanel;
    Label tb = sp.FindName("Label1") as Label;
 
 
}

 

 

 

 

 

 

    <Window x:Class="WpfApp5.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp5"
            xmlns:arr="clr-namespace:System.Collections;assembly=mscorlib"
            xmlns:sys="clr-namespace:System;assembly=mscorlib"
            mc:Ignorable="d"
            Title="MainWindow" Height="450" Width="800">
        <Window.Resources>
            <ControlTemplate x:Key="Temp">
                <StackPanel Background="Yellow">
                    <TextBox x:Name="txt1"/>
                    <TextBox x:Name="txt2"/>
                    <TextBox x:Name="txt3"/>
                </StackPanel>
               
            </ControlTemplate>
        </Window.Resources>
     
     
        <StackPanel >
            <UserControl x:Name="uc" Template="{StaticResource Temp}"></UserControl>
            <Button x:Name="btn" Content="btn" Click="Btn_Click"/>
        </StackPanel>
    </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 WpfApp5
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
     
            private void Btn_Click(object sender, RoutedEventArgs e)
            {
                TextBox tb = this.uc.Template.FindName("txt1", this.uc) as TextBox;
                tb.Text = "Hello,wpf";
                StackPanel sp = tb.Parent as StackPanel;
                (sp.Children[1] as TextBox).Text = "Hello control template";
                (sp.Children[2] as TextBox).Text = "I can find you";
     
            }
        }
    }

 

posted on   宏宇  阅读(262)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
历史上的今天:
2012-08-16 异度传说的世界观
2011-08-16 window7共享xp或者2003的文件设置
2011-08-16 一个字节造成的巨大性能差异——SQL Server存储结构(转)
2007-08-16 博客积分超2W留念
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示