R.Tanaka.Ichiro's Blog

主にC# な話題です

目次

Blog 利用状況

ニュース

XAML でイベントハンドラを登録

http://blogs.wankuma.com/rti/archive/2009/05/21/173327.aspx
WPF のコントロールで ContextMenu

の続きのような、そうでないような・・・


>aetos
>イベントハンドら設定するのも XAML でできるよね?
>-------------------
>R・田中一郎
>なに?
>最近のXAMLは、そんなこともできるか・・・
>調べてみます^^;


ということで調べてみた結果、こんな感じで書けるんですね。


<Button Name="Button1" Click="button1_Click" MouseEnter="button1_MouseEnter">
  Button
</Button>


XAML でイベントハンドラの設定

が書けるなんてびっくり・・・
だって、元々はプログラマとデザイナの分散開発が目的だとイベント系セミナーで叫ばれていた記憶があって、デザイナ側がイベントハンドラ書くって発想がなかったんだもの。

まー、書けないよりは書けた方がいいに決まっているけど、びっくりですね。

投稿日時 : 2009年5月22日 13:11

Feedback

# re: XAML でイベントハンドラを作成 2009/05/22 14:24 aetos

XAML って(UI レイアウト以外の用途もあるが、UI レイアウトに限れば)2つの目的があると思います。
UI の構成の定義と、UI の見た目の定義です。

UI の構成の定義ってのは、どういうコントロールがあって、それはコードとどう結びつくかです。
UI の見た目の定義ってのは、そのコントロールがどこにあって、どういう外見をしているかです。

HTML を例に出せば、HTML(構成の定義)と CSS(見た目の定義)とロジック(サーバーサイドアプリや JavaScript)の3つの構成要素に対して、XAML が HTML と CSS を兼ねていると思うわけです。

長くなりましたが、何が言いたいかというと、完全にデザイナが好き勝手できるのは、HTML で言うところの CSS だけなんですね。
で、XAML は CSS と HTML の役割を兼ねているので、完全にデザイナの担当ってわけでもないんだと。

# re: XAML でイベントハンドラを作成 2009/05/23 13:03 R・田中一郎

この説明はとても納得できますね。

>長くなりましたが、何が言いたいかというと、完全にデザイナが好き勝手できるのは、HTML で言うところの CSS だけなんですね。
>で、XAML は CSS と HTML の役割を兼ねているので、完全にデザイナの担当ってわけでもないんだと。

それは確かにそうだと思うし、分業化できても XAML をデザイナさんに書けと言っても無理だから Expression Blend がはいた XAML を開発者がゴリゴリすることになるのが現実でしょうね。
そういう意味では XAML でイベントハンドラが書けるのは納得できます。

# re: XAML でイベントハンドラを作成 2009/05/24 9:21 もり ひろゆき

推奨されていませんが、XAMLの中でコードだってかけますよ(^^;

# re: XAML でイベントハンドラを作成 2009/05/25 11:13 aetos

> Expression Blend がはいた XAML を開発者がゴリゴリすることになるのが現実でしょうね。

UI の見た目は変わりやすいけど、UI の構成はさほど変わりません。
プログラムの設計でも、「変わりやすさ」に着目した手法ってありますよね。
そういう意味では、変わりやすいものと変わりにくいものが1つのファイルに同居しているのって、あまりいいことじゃないと思います。

理想を言えば、構成の XAML と見た目の XMAL に分けて作れるといいんですよね。XAML 素人だからできるかどうか知らないんですけど。
ベース(構成)を先に作ってから、飾りつけは後でいくらでもしてください、という感じで。ただしその際、デザイナの都合で勝手に構成を変えられちゃ困るわけで。

# re: XAML でイベントハンドラを作成 2009/05/25 13:10 R・田中一郎

もり ひろゆき さん

>推奨されていませんが、XAMLの中でコードだってかけますよ(^^;

なんでもアリですねw

----------------------------------------
aetos さん

>そういう意味では、変わりやすいものと変わりにくいものが1つのファイルに同居しているのって、あまりいいことじゃないと思います。

禿同
WindowsForm ではパーシャルクラスでファイルを分けることで実現していたけど、xaml は今度どうなっていくのだろう。
僕も、こうすべきと言えるくらいの知識がある訳ではないのですけど、イベントハンドラは XAML の中に書くのは嫌だなぁ。

# re: XAML でイベントハンドラを作成 2009/05/25 15:10 trapemiya

>僕も、こうすべきと言えるくらいの知識がある訳ではないのですけど、イベントハンドラは XAML の中に書くのは嫌だなぁ。

コマンドですね。特定のイベントハンドラに結びつける必要がありません。

#イベントハンドラを書くという表現だと、どうもイベントハンドラそのもの(メソッド)を書くように見えてしまうなぁ。

# re: XAML でイベントハンドラを作成 2009/05/25 15:55 R・田中一郎

ん?

イベントハンドラとは、イベントが発生した時の処理で、VB6 だと Form_Load() メソッドそのものですけど、C# の場合は、Click イベントが発生したことによる操作になるという認識ですなのですが違っているのでしょうか?

つまりイベントハンドラとは Click イベントが発生したことによる操作なので button1_MouseEnter メソッドを呼び出すという動作そのものを指すと認識しています。

たとえば、以下の記述がイベントハンドラにあたり、これによって呼び出されるメソッド「this.Button_Click(sender, e)」は、単なるメソッドだという認識です。


button.Click += (sender, e) => this.Button_Click(sender, e);

で、上記の部分にあたるのが XAML の以下のコードの部分です

Click="button1_Click"

ということでイベントハンドラという表現を使ったのですが、根本的に間違っているのかしら?

# re: XAML でイベントハンドラを作成 2009/05/25 16:19 aetos

> button.Click += (sender, e) => this.Button_Click(sender, e);

これは1行にまとまっちゃってますけど、

> (sender, e) => this.Button_Click(sender, e);

↑この部分が「イベントハンドラ本体」で

> button.Click +=

↑この部分が、イベントとイベントハンドラの結びつけ、と分けるという想定ですね。
で、「イベントハンドラを書く」と言うと、前者を書くことに聞こえる、ということだと思います。
# 俺は個人的にはどっちでもいいですけどね。

というか、デザイナを使えば、分かれたコードができますよね。

分けて書けば、

button.Click += button1_Click;



private void button1_Click( ... ) { ... }

に分かれるわけで、これならより、「イベントハンドラ本体」が浮き上がって見えますね。

# re: XAML でイベントハンドラを作成 2009/05/25 17:36 R・田中一郎

XAML の以下の部分

>Click="button1_Click"

は、

button.Click += (s, e) => button_Click(s, e);

と書いたことと同じという解釈なので、この部分がイベントハンドラに相応するという解釈して「イベントハンドラが書ける」と書いたのですが。

あれ?
何か根本的に間違っているのかしら?(?_?)
button_Click(s, e) {} メソッドブロックがイベントハンドラ?

# re: XAML でイベントハンドラを作成 2009/05/25 17:45 aetos

あくまで感覚の問題ですけど、

> Click="button1_Click"



> button.Click += button1_Click;

と同じだという認識です。

# re: XAML でイベントハンドラを作成 2009/05/25 17:51 trapemiya

あれ? 私はイベントハンドラはずっとメソッドのことだと理解してましたが、デリゲートを指したりもするのかな?

Visual Basic および Visual C# のイベント ハンドラ
http://msdn.microsoft.com/ja-jp/library/aa984105(VS.71).aspx

# re: XAML でイベントハンドラを作成 2009/05/25 18:19 R・田中一郎

aetos さん
trapemiya さん

すみません。
何か混乱していますorz

エントリ元の場合は、aetos さんのいう「button.Click += button1_Click;」に相応するという場合、「button1_Click」メソッドブロック本体がイベントハンドラで、XAML に書いているのは「イベントハンドラの登録」になるってことでOKです?

# re: XAML でイベントハンドラを作成 2009/05/25 19:48 trapemiya

>になるってことでOKです?

はい。そう思ってます。Event Handlersなので、イベントを扱う人(処理する人)になると思いますので、少なくとも動作を指している言葉ではないんじゃないかと思います。

# re: XAML でイベントハンドラを作成 2009/05/26 9:46 R・田中一郎

なるほど了解です。

以前どこかで、以下をイベントハンドラと呼んでいる記事を見て、それ以来.NET では以下をイベントハンドラと呼ぶと誤って認識してしまっていたようです。

this.button1.Click += new System.EventHandler(this.button1_Click);

aetos さん 、trapemiya さん、どうもありがとうございました。

# re: XAML でイベントハンドラを登録 2009/05/26 16:08 通りすがり

こういうとき、英語により近いVBだとわかりやすかったりします。

this.button1.Click += new System.EventHandler(this.button1_Click);

これをVBで書くなら、

AddHandler Me.Button1.Click, AddressOf Button1_Click

これだと、この記述自体はHandlerをAddしているもので、HandlerはButton1_Clickメソッドである、ということが明確です。

# re: XAML でイベントハンドラを登録 2009/06/03 17:11 R・田中一郎

VB はキーワードが多い点で、わかりやすい部分もありますよね。

# XAML でイベントハンドラを登録(その2) 2009/06/05 14:15 R.Tanaka.Ichiro's Blog

XAML でイベントハンドラを登録(その2)

# This is a topic that's close to my heart... Best wishes! Exactly where are your contact details though? 2019/04/10 22:48 This is a topic that's close to my heart... Best w

This is a topic that's close to my heart...
Best wishes! Exactly where are your contact details though?

# Having read this I believed it was rather informative. I appreciate you taking the time and energy to put this informative article together. I once again find myself personally spending way too much time both reading and commenting. But so what, it was 2019/05/09 16:16 Having read this I believed it was rather informat

Having read this I believed it was rather informative.

I appreciate you taking the time and energy to put this informative
article together. I once again find myself
personally spending way too much time both reading and commenting.
But so what, it was still worthwhile!

# It's hard to come by knowledgeable people in this particular subject, but you sound like you know what you're talking about! Thanks 2019/05/14 0:11 It's hard to come by knowledgeable people in this

It's hard to come by knowledgeable people in this particular subject, but you sound like you know what
you're talking about! Thanks

# Hello to every body, it's my first pay a quick visit of this website; this web site consists of amazing and in fact excellent data in support of readers. 2019/05/30 17:31 Hello to every body, it's my first pay a quick vis

Hello to every body, it's my first pay a quick visit of this website; this web site consists of amazing and in fact excellent data in support of
readers.

# Great post however , I was wondering if you could write a litte more on this subject? I'd be very thankful if you could elaborate a little bit further. Appreciate it! 2019/05/30 21:12 Great post however , I was wondering if you could

Great post however , I was wondering if you could write a litte more on this
subject? I'd be very thankful if you could
elaborate a little bit further. Appreciate it!

# Why viewers still make use of to read news papers when in this technological globe the whole thing is accessible on net? 2019/06/03 20:44 Why viewers still make use of to read news papers

Why viewers still make use of to read news papers when in this technological globe the whole thing
is accessible on net?

# If you are going for most excellent contents like me, only pay a visit this website daily because it offers quality contents, thanks 2019/06/14 18:48 If you are going for most excellent contents like

If you are going for most excellent contents like me,
only pay a visit this website daily because it offers quality contents,
thanks

# My partner and I stumbled over here different page and thought I should check things out. I like what I see so now i am following you. Look forward to exploring your web page repeatedly. 2019/06/16 22:07 My partner and I stumbled over here different pag

My partner and I stumbled over here different page and thought I
should check things out. I like what I see so now i am following you.
Look forward to exploring your web page repeatedly.

# I truly love your website.. Excellent colors & theme. Did you develop this amazing site yourself? Please reply back as I'm wanting to create my very own blog and would love to know where you got this from or what the theme is named. Thanks! 2019/07/25 18:54 I truly love your website.. Excellent colors &

I truly love your website.. Excellent colors & theme. Did you develop
this amazing site yourself? Please reply back as I'm wanting to create my very own blog
and would love to know where you got this from or what the
theme is named. Thanks!

# I truly love your website.. Excellent colors & theme. Did you develop this amazing site yourself? Please reply back as I'm wanting to create my very own blog and would love to know where you got this from or what the theme is named. Thanks! 2019/07/25 18:55 I truly love your website.. Excellent colors &

I truly love your website.. Excellent colors & theme. Did you develop
this amazing site yourself? Please reply back as I'm wanting to create my very own blog
and would love to know where you got this from or what the
theme is named. Thanks!

# I truly love your website.. Excellent colors & theme. Did you develop this amazing site yourself? Please reply back as I'm wanting to create my very own blog and would love to know where you got this from or what the theme is named. Thanks! 2019/07/25 18:56 I truly love your website.. Excellent colors &

I truly love your website.. Excellent colors & theme. Did you develop
this amazing site yourself? Please reply back as I'm wanting to create my very own blog
and would love to know where you got this from or what the
theme is named. Thanks!

# I truly love your website.. Excellent colors & theme. Did you develop this amazing site yourself? Please reply back as I'm wanting to create my very own blog and would love to know where you got this from or what the theme is named. Thanks! 2019/07/25 18:57 I truly love your website.. Excellent colors &

I truly love your website.. Excellent colors & theme. Did you develop
this amazing site yourself? Please reply back as I'm wanting to create my very own blog
and would love to know where you got this from or what the
theme is named. Thanks!

# Great blog you have here.. It's hard to find high-quality writing like yours these days. I truly appreciate individuals like you! Take care!! 2019/08/24 16:36 Great blog you have here.. It's hard to find high-

Great blog you have here.. It's hard to find high-quality writing like yours these days.
I truly appreciate individuals like you! Take care!!

# Whoa! This blog looks exactly like my old one! It's on a entirely different topic but it has pretty much the same layout and design. Excellent choice of colors! 2019/09/06 23:39 Whoa! This blog looks exactly like my old one! It

Whoa! This blog looks exactly like my old one!
It's on a entirely different topic but it has pretty much the same layout and design. Excellent choice of colors!

# Doctor Bill Clinic, a prominent Beauty and Health Institute, provides a variety of services. Laser, skin cells, high-degree surgery. A medical team to help with skin and surgeon ornaments. FDA certified. The Dark Clinic has 3 branches at present. One of 2021/08/19 23:32 Doctor Bill Clinic, a prominent Beauty and Health

Doctor Bill Clinic, a prominent Beauty and Health
Institute, provides a variety of services. Laser, skin cells, high-degree surgery.
A medical team to help with skin and surgeon ornaments.
FDA certified.

The Dark Clinic has 3 branches at present. One of them is
located in Muang District (Tak Province), and
the other one is in Mae Sot District (Tak
Province). It provides various beauty tips. That focuses
on the importance of the president first

# Doctor Bill Clinic, a prominent Beauty and Health Institute, provides a variety of services. Laser, skin cells, high-degree surgery. A medical team to help with skin and surgeon ornaments. FDA certified. The Dark Clinic has 3 branches at present. One of 2021/08/19 23:32 Doctor Bill Clinic, a prominent Beauty and Health

Doctor Bill Clinic, a prominent Beauty and Health
Institute, provides a variety of services. Laser, skin cells, high-degree surgery.
A medical team to help with skin and surgeon ornaments.
FDA certified.

The Dark Clinic has 3 branches at present. One of them is
located in Muang District (Tak Province), and
the other one is in Mae Sot District (Tak
Province). It provides various beauty tips. That focuses
on the importance of the president first

# Doctor Bill Clinic, a prominent Beauty and Health Institute, provides a variety of services. Laser, skin cells, high-degree surgery. A medical team to help with skin and surgeon ornaments. FDA certified. The Dark Clinic has 3 branches at present. One of 2021/08/19 23:32 Doctor Bill Clinic, a prominent Beauty and Health

Doctor Bill Clinic, a prominent Beauty and Health
Institute, provides a variety of services. Laser, skin cells, high-degree surgery.
A medical team to help with skin and surgeon ornaments.
FDA certified.

The Dark Clinic has 3 branches at present. One of them is
located in Muang District (Tak Province), and
the other one is in Mae Sot District (Tak
Province). It provides various beauty tips. That focuses
on the importance of the president first

# 偽物時計 2021/11/20 15:24 tggvgyirx@livedoor.com

★★ブランド 腕時計★★

◇各種のブランドの財布
安価販売大人気 時計★
高品質の問屋! o(∩_∩)o.
新型は発売して、当社はブランドの専門販売会社です。
★信用第一、良い品質、低価格は 私達の勝ち残りの切り札です。
★ 当社の商品は絶対の自信が御座います。
★ S品質 シリアル付きも有り 付属品完備!
★ 必ずご満足頂ける品質の商品のみ販売しております。
★ 絶対に満足して頂ける品のみ皆様にお届け致します。
★ 税関の没収する商品は再度無料にして発送します
★ 送料無料(日本全国)
★’゜☆.: ’゜☆.: ’゜☆.: ’゜★’゜☆.: ’゜☆.: ’゜☆.: ’゜★
以下は当店の特恵です:
★ 【最大ブランド問屋腕時計 専売店】
偽物時計 https://www.kopi66.com/product/detail.aspx?id=11710

# order stromectol http://stromectolabc.com/
cost of ivermectin 1% cream 2022/02/08 2:41 Busjdhj

order stromectol http://stromectolabc.com/
cost of ivermectin 1% cream

# buy cheap doxycycline online https://doxycyline1st.com/
doxycycline generic 2022/02/26 19:56 Doxycycline

buy cheap doxycycline online https://doxycyline1st.com/
doxycycline generic

# ルイ ヴィトン 歴史 ss 2022/02/28 16:41 ydpguza@hotmail.co.jp

サイフを購入したのですが、発送~受け取りまでとてもスムーズでした。梱包もしっかりしていて、袋でしたが箱が左右に動かないようにエアキャップを詰めてあったり、手紙が添えてあったりと、とても心遣いを感じられて気持ち良く買い物できました!また機会があればこちらで購入したいと思います(^_^)ありがとうございました!
ルイ ヴィトン 歴史 ss https://www.bag37.com/category-932_784.html?alpha_filter_id=2&page=10

# positive singles https://datingtopreview.com/
dating site sign up 2022/10/17 20:32 Dating

positive singles https://datingtopreview.com/
dating site sign up

# best free dating sites https://topdatingsites.fun/
single friends dating 2022/11/15 0:22 DatingTop

best free dating sites https://topdatingsites.fun/
single friends dating

# can you buy prednisone online uk https://prednisonepills.site/
prednisone 20mg price 2022/11/28 23:47 Prednisone

can you buy prednisone online uk https://prednisonepills.site/
prednisone 20mg price

# meet women online https://datingonline1st.com/
plenty of fish login page 2023/01/17 22:26 Dating

meet women online https://datingonline1st.com/
plenty of fish login page

# chlorhexidine mouthwash over the counter https://overthecounter.pro/# 2023/05/08 18:11 OtcJikoliuj

chlorhexidine mouthwash over the counter https://overthecounter.pro/#

# gnc ed pills https://edpill.pro/# - otc ed pills 2023/06/27 10:14 EdPills

gnc ed pills https://edpill.pro/# - otc ed pills

# medications for ed https://edpills.ink/# - male erection pills 2023/07/26 20:01 EdPills

medications for ed https://edpills.ink/# - male erection pills

# ed meds online without doctor prescription https://edpillsotc.store/# - non prescription erection pills 2023/10/07 21:13 EdPills

ed meds online without doctor prescription https://edpillsotc.store/# - non prescription erection pills

# order valtrex online canada https://valtrex.auction/ buy valtrex australia 2023/10/24 17:41 Valtrex

order valtrex online canada https://valtrex.auction/ buy valtrex australia

# ï»¿paxlovid https://paxlovid.bid/ paxlovid price 2023/10/25 18:23 Paxlovid

paxlovid https://paxlovid.bid/ paxlovid price

# ブレゲ時計 評判 2023/11/08 2:23 fiivlwdgdeh@docomo.ne.jp

とても迅速な対応で良かったです!
また買いたいものがあったら、こちらで探そうと思っています。
購入したお財布も、とても使いやすく気に入っているので、大切にします!
ブレゲ時計 評判 https://www.bagtojapan.com/product/736.htm

# doxycycline 50 mg https://doxycycline.forum/ doxycycline pills 2023/11/25 9:04 Doxycycline

doxycycline 50 mg https://doxycycline.forum/ doxycycline pills

# acquisto farmaci con ricetta https://farmaciait.pro/ acquisto farmaci con ricetta 2023/12/04 7:03 Farmacia

acquisto farmaci con ricetta https://farmaciait.pro/ acquisto farmaci con ricetta

# prednisone 10 mg online https://prednisone.bid/ buy prednisone nz 2023/12/27 6:51 Prednisone

prednisone 10 mg online https://prednisone.bid/ buy prednisone nz

# African Media Emphasize: Put off Informed on Celebrities & Trends! 2024/03/26 2:35 Jackieles

In our online broadside, we strive to be your secure source into the latest scuttlebutt take media personalities in Africa. We settle staunch attention to promptly covering the most fitting events with regard to illustrious figures on this continent.

Africa is well-heeled in talents and sui generis voices that hack the cultural and social countryside of the continent. We distinct not only on celebrities and showbiz stars but also on those who compel significant contributions in numerous fields, be it knowledge, manoeuvring, science, or philanthropy https://afriquestories.com/page/8/

Our articles lay down readers with a comprehensive overview of what is happening in the lives of media personalities in Africa: from the latest dirt and events to analyzing their influence on society. We keep road of actors, musicians, politicians, athletes, and other celebrities to provide you with the freshest news firsthand.

Whether it's an limited sound out with a revered star, an review into disreputable events, or a review of the latest trends in the African showbiz humanity, we strive to be your rudimentary outset of report back media personalities in Africa. Subscribe to our broadside to hamper informed back the hottest events and fascinating stories from this captivating continent.

タイトル
名前
Url
コメント