かずきのBlog

C#やJavaやRubyとメモ書き

目次

Blog 利用状況

ニュース

わんくまBlogが不安定になったため、前に書いてたはてなダイアリーにメインを移動します。
かずきのBlog@Hatena
技術的なネタは、こちらにも、はてなへのリンクという形で掲載しますが、雑多ネタははてなダイアリーだけに掲載することが多いと思います。
コメント
プログラマ的自己紹介
お気に入りのツール/IDE
プロフィール
経歴
広告
アクセサリ

書庫

日記カテゴリ

[WPF][C#]コマンドですぞ その6「ICommandSource」

その1「ICommandインターフェース」:http://blogs.wankuma.com/kazuki/archive/2008/03/16/127903.aspx
その2「GUIにコマンドを結びつける」:http://blogs.wankuma.com/kazuki/archive/2008/03/16/127927.aspx
その3「ショートカットとコマンドを結びつける」:http://blogs.wankuma.com/kazuki/archive/2008/03/16/127931.aspx
その4「ショートカットとコマンドを結びつけるXAML版」:http://blogs.wankuma.com/kazuki/archive/2008/03/16/127934.aspx
その5「RoutedCommand」:http://blogs.wankuma.com/kazuki/archive/2008/03/16/127942.aspx

今までコマンドはCommandプロパティに入れればいいんだ!みたいに乱暴に言ってたけど、このCommandプロパティってどういうものなの?ということに触れてみたいと思う。

このCommandプロパティは、System.Widows.Input.ICommandSourceというインターフェイスで定義されている。
メニューやボタンは、このインターフェイス(厳密にはButtonじゃなくてButtonBaseとかだけど)を実装するかたちで定義されている。

ICommandSourceには、今まで使ってきたCommandプロパティ以外にも2つのプロパティが定義されている。ICommandSourceの定義はたぶんこんな感じになってるはず。

interface ICommandSource {
  Object CommandParameter { get; }
  IInputElement CommandTarget { get; }
  ICommand Command { get; }
}

プロパティが全部getだけなのは、コマンドの設定方法は実装側で好きにしてくれ!という意思に現れなんだろうか?
確かに、コマンドの実行方法を統一するだけならget出来れば無問題だ。

当然ながら、ICommandSourceを実装すれば自前のクラスにもコマンド対応!!とかできる。
実装例がMSDNにあったので、そっちを見ればOK。

方法:ICommandSourceを実装する http://technet.microsoft.com/ja-jp/library/ms748978(VS.85).aspx

実装自体は、めんどくさいが簡単にできる。
因みに注意が必要なのは、CommandTargetプロパティは、CommandプロパティのインスタンスがRoutedCommandじゃないと無意味という仕様になってる。
こんな超汎用的な部分からRoutedCommandって優遇されてるみたい。

投稿日時 : 2008年3月18日 0:16

Feedback

# re: [WPF][C#]コマンドですぞ その6「ICommandSource」 2008/03/18 12:56 Streetw☆

>プロパティが全部getだけ

getだけのインターフェイスは参照のみと思いこんでいたので、すごく違和感あります。
それとこれまでのシリーズ見させてもらっていて、Commandは代入して使う物と覚えようとしてましたし。
私はまだ「コマンドですか??」という状態なんですが、「好きにしてくれ!」について考えました。

1.このInterfaceは「コマンドを呼び出す方法」なので、そのコマンドの入手方法については関与しない。
2.Commandの参照時に戻すICommandは、いつも外から設定されるばかりじゃない。

当たってますか?
インターフェイスってじっっっくり考えられてると思うから、もっと勉強すればgetだけになってる背景がわかるようになるんでしょうか。。。

それと、ヘルプを見るとVisual Basicの定義では「ReadOnly Property」ってなってるから、Visual Basicでの実装はどうするのかなって試してみると、実装にReadOnlyがついちゃってSetが書けないみたい??
ReadOnlyを消してSetを書いてもエラーになるし、ImplementsしないWriteOnlyな同名のプロパティを書いてもエラーになるし。
「VB ICommandSource」で検索すると、日本語のページではココがトップでした(^-^)

長くなりました。すみません;

# re: [WPF][C#]コマンドですぞ その6「ICommandSource」 2008/03/19 10:07 かずき

私もsetできるようなインターフェースにしなかった理由がよくわかりません(笑)

確かに下のようにコマンドを実行するためのコードにはgetしかいらないんですよね。
ICommandSource source = どっかからのインスタンス;
ICommand command = source.Command;
command.Execute(source.CommandParameter);

# re: [WPF][C#]コマンドですぞ その6「ICommandSource」 2008/03/19 15:46 Streetw☆

・使う側ではgetだけあれば十分。
・実装する側はたいていはsetも必要だけど、必要なら勝手に書く。
 でも、Visual Basicでは勝手には書けないorz
ということですかね。

C#でも「インターフェイスの明示的な実装」ではsetは書けないから、
ButtonBaseのCommandでは「明示的ではない実装」になってました。
Visual Basicでは「明示的ではない実装」はできないから、
Visual Basicを使う人にとってはこのinterfaceって今後問題になるんじゃないですかね。
#実装する人は少ないと思いますけど。
ちょっと話がそれちゃって(最初から?w)、ごめんなさい~

# [C#][WPF]コマンドですぞ その7「RoutedUICommand」 2008/03/20 14:40 かずきのBlog

[C#][WPF]コマンドですぞ その7「RoutedUICommand」

# re: [WPF][C#]コマンドですぞ その6「ICommandSource」 2008/03/22 0:29 かずき

コンポーネント内部で独自にコマンドのインスタンスを作って返すこともあるかもしれないですからね...
あんまなさそうですけどw

# CaBpYodPGchhNlM 2012/01/07 7:45 http://www.luckyvitamin.com/c-390-maca

Read, of course, far from my topic. But still, we can work together. How do you feel about trust management?!...

# Cheap Canada Goose 2012/10/19 15:20 http://www.supercoatsale.com

Great website. A lot of helpful information here. I am sending it to a few friends ans also sharing in delicious. And of course, thanks to your sweat!

# wallet 2012/10/26 3:48 http://www.burberryoutletscarfsale.com/accessories

I have not checked in here for a while because I thought it was getting boring, but the last several posts are good quality so I guess I'll add you back to my everyday bloglist. You deserve it friend :)
wallet http://www.burberryoutletscarfsale.com/accessories/burberry-wallets-2012.html

# Burberry Watches 2012/10/26 3:48 http://www.burberryoutletscarfsale.com/accessories

you are truly a just right webmaster. The site loading pace is incredible. It kind of feels that you are doing any unique trick. Also, The contents are masterpiece. you've done a fantastic activity on this matter!
Burberry Watches http://www.burberryoutletscarfsale.com/accessories/burberry-watches.html

# cheap tie 2012/10/26 3:49 http://www.burberryoutletscarfsale.com/accessories

I gotta favorite this website it seems very helpful very helpful
cheap tie http://www.burberryoutletscarfsale.com/accessories/burberry-ties.html

# cheap burberry bags 2012/10/26 3:49 http://www.burberryoutletscarfsale.com/burberry-ba

I really like your writing style, fantastic info , thanks for posting : D.
cheap burberry bags http://www.burberryoutletscarfsale.com/burberry-bags.html

# mens shirts 2012/10/27 19:11 http://www.burberryoutletonlineshopping.com/burber

What i don't realize is actually how you are not actually a lot more neatly-liked than you may be now. You're very intelligent. You realize therefore considerably with regards to this matter, made me personally believe it from a lot of various angles. Its like men and women aren't fascinated unless it is something to do with Woman gaga! Your personal stuffs great. At all times handle it up!
mens shirts http://www.burberryoutletonlineshopping.com/burberry-men-shirts.html

# Burberry Watches 2012/10/27 19:11 http://www.burberryoutletonlineshopping.com/burber

Some really great information, Gladiolus I discovered this. "The historian must have some conceptions of how men who are not historians behave." by Edward Morgan Forster.
Burberry Watches http://www.burberryoutletonlineshopping.com/burberry-watches.html

# t shirts 2012/10/27 19:11 http://www.burberryoutletonlineshopping.com/burber

I was looking at some of your articles on this internet site and I believe this internet site is really instructive! Keep on posting.
t shirts http://www.burberryoutletonlineshopping.com/burberry-womens-shirts.html

# Nike Schehe 2012/10/30 18:54 http://www.nikefree3runschuhe.com/

Never individual is definitely worth any cry, as well as the person who can be won‘big t get you to watchword.
Nike Schehe http://www.nikefree3runschuhe.com/

# mens shirts 2012/11/02 22:37 http://www.burberryoutletscarfsale.com/burberry-me

Simply wanna comment on few general things, The website design is perfect, the content is rattling superb. "The idea of God is the sole wrong for which I cannot forgive mankind." by Marquis de Sade.
mens shirts http://www.burberryoutletscarfsale.com/burberry-men-shirts.html

# Canada Goose Outlet 2012/11/03 4:58 http://www.supercoatsale.com

I really like your writing style, great info , thankyou for posting : D.
Canada Goose Outlet http://www.supercoatsale.com

# burberry outlet 2012/11/05 20:59 http://www.burberryoutletonlineshopping.com/burber

You have brought up a very great details , appreciate it for the post.
burberry outlet http://www.burberryoutletonlineshopping.com/burberry-tote-bags.html

# GXcTSujivlySGA 2014/07/19 3:28 http://crorkz.com/

EmiObk Thanks a lot for the blog. Really Great.

# GLigXmSRXnGNBYPBv 2014/08/27 12:34 http://crorkz.com/

gCA9lr wonderful post, very informative. I'm wondering why the other experts of this sector don't understand this. You must continue your writing. I am confident, you've a huge readers' base already!

# ZNoyYvlOBdGwxtoqlw 2014/09/05 22:53 https://www.youtube.com/watch?v=bmyZcX8nn50

F*ckin' amazing things here. I am very satisfied to peer your article. Thanks a lot and i'm taking a look forward to contact you. Will you please drop me a e-mail?

# veAGlAjVCdKreYmT 2014/09/11 17:07 http://swiss-vps.com/products/windows-vps/

you've an important blog here! would you like to make some invite posts on my blog?

# dxNGNeyvSFC 2014/09/14 7:51 http://www.needpeep.com/

great publish, very informative. I ponder why the other experts of this sector don't realize this. You must proceed your writing. I am sure, you've a great readers' base already!

# yjexECzZQItIq 2014/09/17 6:18 http://theboatonlinestore.es/

I will immediately clutch your rss feed as I can not in finding your email subscription link or newsletter service. Do you've any? Kindly let me recognize in order that I may just subscribe. Thanks.

# ADFFbnUcOOqiis 2014/09/17 19:10 http://track.oainternetservices.com/doIn?id=505673

I savour, result in I found exactly what I used to be having a look for. You've ended my 4 day lengthy hunt! God Bless you man. Have a great day. Bye

# ujCCavyzlFEorvat 2015/01/09 15:11 marcus

ThL5xf http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com

# rYjutlqhamRw 2015/01/27 22:30 Brooke

Where are you from? http://www.beachinthecity.com/index.php/programm limovan online Like Facebook, Twitter is pinning it hopes on advertisers looking to tap its member base of 200 million regular users. It is setting its sights on TV, the most lucrative advertising market, and playing up to media companies and major brands its appeal to viewers who use the 140-character messaging platform to discuss what they are watching.

# gNqYMdOlSCAgUswKT 2015/01/29 3:56 Raleigh

I have my own business http://www.centernewton.org/plan/ buy clonazepam pills online I’ve assumed that you won’t want the bother of letting and managing the property yourself. Personally, I don’t have the time, but if you do then go for it – but do it right.

# CSYGVbVdnFviSrD 2015/01/29 3:56 Antoine

Who would I report to? http://www.video-to-flash.com/video_to_flv/ 2mg clonazepam and alcohol Volgograd lies 650 kilometers (400 miles) northeast of the North Caucasus, where an Islamic insurgency has been simmering for more than a decade after two separatist wars in Chechnya. In Dagestan, the center of the insurgency, bombings and shootings occur almost daily. The Tsarnaev brothers, accused of carrying out the Boston Marathon bombings, have roots in Dagestan and Chechnya.

# DALCqzaXiKYanBfdlh 2015/01/29 3:57 Mario

I've come to collect a parcel http://nitanaldi.com/nita-hq/ how many hydrocodone 500 mg get you high Since taking office last December, Mexican President EnriquePena Nieto has proposed a slew of reforms to tackle the lack ofcompetition in Mexico's telecom and energy sectors, as well as atax overhaul that will introduce a capital gains tax, amongother measures aimed at boosting the country's coffers.

# erXvjeMSQbj 2015/02/05 20:05 Ricardo

Can I use your phone? http://www.blue-lemons.com/about buy levofloxacin online uk "If you look at oil spills which happen in tropical waters, normally within a few years you don't find the oil anymore," he said, "because there are bacteria which actually absorb the oil and the oil disappears.

# bkAPhcLyLSzPq 2015/02/06 6:22 Moses

About a year http://sinestezia.com/publications/ tsb loans Carnival dropped 5.7 percent to 21.30 pounds, the FTSE 100'stop faller for the second session in a row, after Tuesday'swarning of a possible loss prompted Morgan Stanley to downgradethe cruise operator to 'underweight'. Several other banks alsocut price targets for the stock.

# ejISFIUEdSqPUJZG 2015/02/07 0:41 Clement

Free medical insurance http://www.racc.org/about/equity purchase quetiapine online Some experts suggest that producing fuel from seaweed is too expensive to make it viable as a business, but these researchers say they could have commercial-scale farms within a decade. Selling the seaweed for other purposes - as a food or a cosmetic ingredient for example - could increase the value of the crop.

# pQSVyITcTPVedUPPMSQ 2015/02/08 23:34 Elroy

I really like swimming http://www.sporttaplalkozas.com/sporttaplalkozas/eletmod-program debt cosolidation It also recommended that well-run councils or high streets should be "left to their own devices" as they already catered for local demand, while those in charge of poorly run high streets which have the potential to flourish should have their powers transferred to management companies with retail experience.

# TIxBPYxHAAQ 2015/02/08 23:34 Rudolph

The National Gallery http://atecuccod.com/index.php/kapcsolat apply for finance The league didn’t immediately impose a penalty because Hill tried to fight it. He was also suspended for four games early last season for using a performance-enhancing drug, which he and the team said was Adderall.

# bLfkKoTZnQTQv 2015/02/08 23:35 Alonso

I study here http://www.sporttaplalkozas.com/sporttaplalkozas/fogyokura-program does loan companies ask for a percent In the early days of Bebo the hardest daily decision was who deserved your Luv for the day. Bebo's 'Share the Luv' button allowed users to display a small red heart graphic in messages to their friends. Initially, each user was restricted to giving one heart a day, and the amount of hearts you won over was indicative of popularity. Then you were allowed to share three Luvs a day, which made everything less special, and in hindsight was clearly the beginning of the end.

# WZkGgYUsDZ 2015/02/08 23:35 Leonard

How do you do? http://atecuccod.com/index.php/nyomtatas www.cashloan network.com LONDON--The U.K. Society of Motor Manufacturers and Traders, or SMMT, said Thursday car manufacturing rose 7% in July to 128,873 units, supporting a 1.9% increase in the year so far, adding that it is starting to see slight signs of recovery from Europe.

# earZtKAVgzUesLFYnX 2015/02/09 8:52 Rickey

A pension scheme http://www.borda-net.org/browse/6.html erythromycin tablets bp 250 mg acne �Our aim is the full restoration of the rights of the Palestinian people. In other words, we aim at the destruction of the State of Israel. The immediate aim: perfection of Arab military might. The national aim: the eradication of Israel.� � President Nasser of Egypt, November 18, 1965

# YIXzaHhnRiBGiizim 2015/02/10 7:58 Kylie

We were at school together http://compostcrew.com/faq/ instant loans in accra â€?We are looking at whether we can run a more efficient service, which offers local alternatives for workplace donors while still providing hospitals with the blood they need when patients need it.. 

# oxLSiSIuuDe 2015/02/10 13:33 Isaias

I love this site http://poderesmentales.com/duocobra/ Keflex Dose It truly is a race against time. This summer, Smith finally identified a model from a 1960 cover as Dolores Greer of Southern California, only to learn she had died just days before at the age of 81. Greer�s daughter offered to sign the cover in her mother�s honor, but Smith declined � he only collects autographs from the models themselves.

# QLqkJkagqLYKwUkNto 2015/02/10 13:34 Carlos

The United States http://www.milliput.com/about.html Aciclovir Tablets Buy Online Having launched its intense burst of stimulus in April, the BOJ does not want to act again easily. But it has not ruled out expanding stimulus if the damage from the tax hike proves bigger than expected and threatens achievement of 2 percent inflation.

# DPOkNutFVLAj 2015/02/11 16:04 Giuseppe

I'll put him on http://www.wildfirerhc.org/about/ get credit repair The researchers say carbon-dating tests on three of eight skeletons exhumed from the Saint Orsola convent are under way and they will do the same with the contents of the Giocondo tomb - although it could take a year before the DNA testing process is started.

# PeTQGQwLzF 2015/02/11 16:04 Charley

I'm unemployed http://thisisaway.org/get-involved/ bank poor credit It's really amazing to see all the neocon posters on this site in their futile attempts to bend, twist, and utterly distort the facts of this government shutdown. Make no mistake, this is a teabagger-generated shutdown, period. End of story, people. They (the 'baggers) have chosen to take budget negotiations and turn them into their own pathetic ideological crusade against the Affordable Care Act. And they will lose. In time, the American people will all see that. The utter hatred and contempt the 'baggers have displayed toward this President is unprecendented and quite frankly, disgusting!! And the sad part is, these pathetic souls don't care. It is their fault, simply put. The ACA is the law of the land and cannot be defunded. What really scares these morons is not whether the ACA will fail, rather, they know it will succeed in its purpose and become popular. And when that happens, you won't hear even one them refer to it as Obamacare any more!

# APfhMOZwRpMCg 2015/02/11 16:04 Harvey

I work for a publishers http://esuf.org/about/ online cash management It could mean no more having to check up on Mom or Dad every morning: Motion sensors on the wall and a monitor under the mattress one day might automatically alert you to early signs of trouble well before an elderly loved one gets sick or suffers a fall.

# acPwxFADPMYTJ 2015/02/11 16:04 Ashley

Do you know the number for ? https://josbinder.at/index.php?nav=37 personal loans instant cash SAN FRANCISCO/LOS ANGELES, Aug 12 (Reuters) - California,whose green ambitions helped the solar and wind industries takeroot, is taking an essential next step by proposing a sharp risein energy storage to better integrate renewable power with therest of the grid.

# qeOOyHmAdLwTSXm 2015/02/26 18:47 Jerome

About a year http://www.angleseyonline.com/optimisation.html generic endep Brett thought the umpires were checking for a corked bat. No worries, he figured. Then suddenly he was called out, for one of the dumbest reasons ever. He sprinted for home plate � we�ve all seen the tantrum, a hundred times � and the real fun began.

# viDcRUScJY 2015/02/28 5:04 Prince

We've got a joint account http://version22.com/contact/ latanoprost eye drops for dogs But more importantly, it also speaks to the very broad definition that the JOBS Act applied to "emerging" businesses. When a large company like Twitter qualifies for that kind of special provision, it poses the question of what companies wouldn't qualify – not to mention whether Twitter wouldn't have filed for its IPO without the special JOBS Act provision.

# ExRSMVFwQJ 2015/02/28 5:04 Friend35

I've been cut off http://www.bethelhebrew.org/about-us Buy Cardura Online Under the skin, Vauxhall has been playing with the SuperSport’s all wheel drive chassis and have changed around 60 per cent of the rear suspension’s components to deliver a significant handling improvement, with better damping giving an improved ride.

# NRSSgKBIltprOGCfTv 2015/02/28 5:04 Teodoro

Incorrect PIN https://rarcc.org/contact-us order bimatoprost The report is the last major indicator the Fed sees before it decides this month whether or not to pull back on its massive bond-buying program, a stimulus plan that has kept interest rates low and supported stocks for months. Most investors believe the Fed will begin to pull back this month. But Friday’s jobs report makes that slightly less certain.

# qdcRbogItHCKVpSoc 2015/04/07 20:44 Orlando

A financial advisor http://www.vaimnemaailm.ee/index.php/tegevused endep 10 tablets There are only limited sizes left of these Leeloos, so get a pair while you can. If you miss out, we love these Rag & Bone at Net-A-Porter super skinnies, or mix things up a bit in some black trousers with white side stripes at ASOS and Boohoo.

タイトル  
名前  
Url
コメント