Visual Studio / WPF > object > 03 sender是什么 > senderに基づく処理
6038 ワード
動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2
03 sender是什么
https://www.youtube.com/watch?v=VnaZpOif8DU&t=182s&list=PLaYqF7AnyNPfTfZiGqTwedIKW_FkZv4Xj&index=3
button2_Click()のsenderを使った例。
2:00ころから。
試してみた。
MainWindow.xaml
<Window x:Class="_170508_t0715_sender.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:_170508_t0715_sender"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Button1" Click="Button_Click"/>
</Grid>
</Window>
MainWindow.xaml.cs
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 _170508_t0715_sender
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
btn.Content = "Clicked";
}
}
}
補足事項
「senderが何か」に基づいて処理を分岐するというのはC++ Builderでもよく使った。
senderに基づく共通処理を実装して、複数のコントロールでのClickイベントにその共通処理を割り当てる、というような使い方。
中国語
sender是什么
http://cjjc.weblio.jp/content/%E4%BB%80%E4%B9%88
是什么 (shi・shén・me)
意訳「sender。これ何ですか?」
Author And Source
この問題について(Visual Studio / WPF > object > 03 sender是什么 > senderに基づく処理), 我々は、より多くの情報をここで見つけました https://qiita.com/7of9/items/0544ad186dca08d4c890著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .