首页 > 其他分享 >dotnet wpf 点击事件

dotnet wpf 点击事件

时间:2024-01-24 13:23:15浏览次数:27  
标签:Windows System 点击 dotnet using wpf MainWindow txtName

secs_wpf\MainWindow.xaml.cs

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 secs_wpf
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void ButtonAddName_Click(object sender, RoutedEventArgs e)
        {

            if (!string.IsNullOrWhiteSpace(txtName.Text) && !lstNames.Items.Contains(txtName.Text))
            {
                lstNames.Items.Add(txtName.Text);
                txtName.Clear();
            }
        }
    }
}

secs_wpf\MainWindow.xaml

<Window x:Class="secs_wpf.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:secs_wpf"
        mc:Ignorable="d"
        Title="SecsTest" Height="450" Width="800">
    <Grid Margin="10">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Label Grid.Column="0" Grid.Row="0">Names</Label>
        <!-- lstNames.Items.Add(txtName.Text); -->
        <ListBox Grid.Column="0"  Grid.Row="1" x:Name="lstNames" />


        <StackPanel Grid.Row="1" Grid.Column="1" Margin="5,0,0,0">
            <TextBox x:Name="txtName" />
            <!-- private void ButtonAddName_Click(object sender, RoutedEventArgs e) -->
            <Button x:Name="btnAdd" Margin="0,5,0,0" Click="ButtonAddName_Click">Add Name</Button>
        </StackPanel>


    </Grid>

</Window>

标签:Windows,System,点击,dotnet,using,wpf,MainWindow,txtName
From: https://www.cnblogs.com/zhuoss/p/17984468

相关文章

  • wpf第九个画面
    主要使用的控件:Grid控件、TabControl控件、DataGrid控件、Button控件、TextBlock控件、TextBox控件 公共属性 HorizontalAlignment:水平显示位置 VerticalAlignment:垂直显示位置 Weight:宽度 Height:高度  Grid控件关键属性:ColumnDefinitions和RowDefinitions,......
  • dotnet 扩展Service方法 secs4net
    secs_learn/Program.csusingDeviceWorkerService;usingMicrosoft.Extensions.DependencyInjection;usingMicrosoft.Extensions.Hosting;Host.CreateDefaultBuilder(args).ConfigureServices((hostContext,services)=>{services.AddSecs4Net&l......
  • dotnet注册服务 secs4net secs
    secs_learn/Program.cs此文件是应用程序的入口点,用于配置和启动主机。使用Host.CreateDefaultBuilder(args)创建一个默认配置的主机构建器,自动加载环境变量、配置文件等设置。.ConfigureServices(...)方法中,通过services.AddHostedService<DeviceWorker>()注册DeviceWor......
  • [element-ui] table表格点击单元格,单元格改变背景色
     <el-table:data="tableData"border@cell-click="cellclick":cell-style="tableCellStyle"></el-table>data(){row:'',column:''}cellclick(row,column,cell......
  • vue-helper 点击跳转插件 在 methods里面互相调用函数,会产生两个函数definitions ,然后
    vue-helper点击跳转插件在methods里面互相调用函数,会产生两个函数definitions,然后就回弹出框让你选择原因:换了台电脑,又从新配置下vscode"editor.gotoLocation.multipleTypeDefinitions":"goto","editor.gotoLocation.multipleReferences":"goto","editor.got......
  • WPF动画
    1、DoubleAnimationprivatevoidRunAnimation(UIElementelement,DependencyPropertydp,doubleoldValue,doublenewValue,doubledurationMs){varduration=newDuration(TimeSpan.FromMilliseconds(durationMs));vardoubleAnima......
  • wpf第八个画面
    主要使用了Grid控件、Border控件、TabControl控件、Textblock控件、Textbox控件、DataGrid控件、Button控件公共属性HorizontalAlignment:水平显示位置VerticalAlignment:垂直显示位置Weight:宽度Height:高度Grid控件 ColumnDefinitions和RowDefinitions,分别表示列的数量集合......
  • .NET Framework中关于WPF的更新信息
    .NETFramework3.0版中的新增功能更新:2007年11月单独发布.NETFramework3.0版是为了在.NETFramework和Windows软件开发包(SDK)中包含以下技术。WindowsCommunicationFoundationWindowsPresentationFoundationUnderstandingWindowsWorkflowFoundation......
  • WPF 使用CommunityToolkit.Mvvm实现Binding示例
    WPF在国内的发展一言难尽。属于那种死不死,活不活的状态。现在应用最多的场景就是上位机了。最近研究了一下WPF中重要的特性之一Binding。如果你没有学会它,基本WPF就没有学明白。研究Binding的时候,我也用了MVVM特性,这也是WPF必学的科目之一。我原来用的是MVVMLight。可是后来......
  • wpf 使用CommunityToolKit.Mvvm实现绑定验证
    接上一个文章,我们在上一个文章中使用CommunityToolKit.Mvvm写了绑定。我们在这篇文章中,写一下绑定验证。绑定验证在WPF系统中也是非常重要的一环。验证可以使得你的系统变得非常健壮。除非你的系统是游戏级别的自娱自乐级别。要么我都建议你加上验证。还是那句老话,写程序一定要......