えムナウ Blog

えムナウ の なすがまま

目次

Blog 利用状況

ニュース


follow mnow at http://twitter.com


えムナウのプログラミングのページ

INETAJ

MSMVP for C#
2005/01-2009/12

書庫

日記カテゴリ

ギャラリ

2009年7月1日 #

INETA Day 2009~コミュニティパワーをリアルに体験しよう

スピーカ陣も豪華です。
聞き逃す手はないと思えるラインナップです。
参加予定の方はお早めに参加登録をしていただけると助かります。
出来れば皆様方のBlogで参加を呼び掛けていただけるとありがたいです。
ご協力ください。よろしくお願いします。
http://www.ineta.jp/tabid/232/Default.aspx

posted @ 18:04 | Feedback (0)

2009年6月30日 #

tech-ed と ReMIX

ことしも tech-ed の季節がやってきます。
今なら早期割引期間中です。
http://www.microsoft.com/japan/teched/2009/default.mspx

 

TechNet Plus Direct サブスクリプション 参加者全員に進呈 | Microsoft Tech·Ed Japan 20092,000 人の IT エンジニアが集う 3 日限りの真夏の祭典 | Microsoft Tech·Ed Japan 2009今夏注目の新製品を徹底解説 | Microsoft Tech·Ed Japan 2009

 

そしてその前にあるのがReMIXです。
ReMIXのページはこちらです。
http://www.microsoft.com/japan/events/remix/2009/default.aspx

私は両方参加する予定です。

posted @ 17:43 | Feedback (0)

2009年6月28日 #

2つの勉強会

2009/06/27 わんくま東京#35
http://www.wankuma.com/seminar/20090627tokyo35/Default.aspx
「VisualStudio2010 β1 を使ってみた」というネタでスピーカをやりました。
TFS以外のVisualStudio2010 β1をなるべくいっぱい紹介しました。
用意したデモは全部はやれなかったけど50分という枠ではしょうがないことです。
PPTを私のサイトで公開しています。
http://www.mnow.jp/tabid/220/Default.aspx
http://mnow.jp/tabid/220/Default.aspx


こみゅぷらす Community Launch 2009 ~Windows 7 コミュニティ勉強会 with Tech Fielders 東京編~
http://comuplus.net/clt2009/
INETAJ と こみゅぷらす 主催の勉強会です。
わんくま東京#35のスピーカが終わってから参加しました。
こちらは懇親会の2次会まで参加しました。
0次会:Microsoft内でハッピーアワー。ビール片手に語り合い。
1次会:風風亭で流し焼き肉。焼き肉のお世話係。別テーブルではAdmintechの懇親会も開かれていました。
2次会:Admintechのお二人と1次会参加された若き有望な三人と語り合い。IT系とDEV系の交流の必要性を実感した。

わんくま東京勉強会に御参加の皆様、スタッフの皆様お疲れさまでした。
Community Launch 2009に御参加の皆様、スタッフの皆様お疲れさまでした。

posted @ 11:49 | Feedback (0)

2009年6月26日 #

INETA Day 2009~コミュニティパワーをリアルに体験しよう

私もスピーカやりますが、「萩原さんのクラウド」「森屋さんのAzure」「小島さんのVisual Studio 2010」聞きたいのだらけです。
分身の術を使いたいくらい。
みなさんもぜひ参加してください。
http://www.ineta.jp/tabid/232/Default.aspx


~~~~~~
<開催概要>
開催日程 2009年7月11日(土)13:00-17:30(受付開始12:15)
会 場 日本科学未来館( http://www.miraikan.jst.go.jp/roomrental/ )
・みらいCANホール(受付)(7F)
・会議室1(7F)
・会議室2(7F)
〒135-0064
東京都江東区青海2-41 日本科学未来館 TEL :03-3570-9151(代表)
<地図 http://www.miraikan.jst.go.jp/guide/route/ >
アクセス:
〇新交通ゆりかもめ「船の科学館駅」下車、徒歩約5分
または 「テレコムセンター駅」下車、徒歩約4分
定 員 300名
参加費 無料(事前登録制)
<セッション詳細>
【最新技術トラック】
S1-1 13:00-14:15(75)
Microsoft ソフトウェアアーキテクト 萩原正義「クラウドでのアーキテクチャの原則と考慮点」Azure Services Platformなどのクラウドでアーキテクチャを構築する場合の原則と、設計のための考慮点を解説します。今後デザインパターンや開発方法論などの整備が行われる過渡期にある現状での最新技術を紹介します。
S1-2 14:30-15:45(75)
株式会社アークウェイ 代表取締役 森屋英治
「Windows Azure アーキテクチャと開発」
第三のプラットフォームWindows Azureの概要をお伝えするとともに、開発者にとってのWindows Azureをどのようにとらえるべきかを
アーキテクチャ解説とCodeを通じて説明していきます。
S1-3 16:00-17:15(75)
VSUG こみゅぷらす 小島 富治雄
『C#4.0 と Visual Studio 2010/.NET Framework 4.0~ここが Cool! いけてる機能10連発!~』
6月に公開されたばかりの Visual Studio 2010 Beta 1 を使って、C#4.0 と Visual Studio 2010/.NET Framework 4.0 いけてる、
お勧めの機能を、どんどんとデモで紹介します。
【コミュニティトラック】
S2-1 13:00-13:40(40)
未定
S2-2 13:45-14:25(40)
インフラジスティックス・ジャパン(株) デベロッパー エバンジェリスト 池原 大然
(アイネタビューロ登録スピーカー)
「未定」
S2-3 14:30-15:10(40)
WisdomSoft赤坂玲音
Silverlight カスタムコントロール開発
通常の Silverlight アプリケーション開発プロジェクトでは UserControlクラスを継承させて標準コントロールなどを貼り付けますが、
再利用可能な汎用的なカスタムコントロールを作成には Visual Studio標準の開発モデルを適用できません。カスタムコントロールを作成するには、
Control クラスから派生する新しいコントロールを用意して、適切に XAML と結合しなければなりません。
本セッションでは、テンプレートやスタイルなど、XAMLによってコントロールが描画される仕組みについてサンプルを含めて紹介し、
独自の外観や振舞いを提供するカスタムコントロールの開発方法を説明します。
S2-4 15:15-15:55(40)
.Netユーザーエクスペリエンス研究所 児玉宏之
WPFの新しいコントロール
WPFのDataGrid・DatePicker・Ribbon・WPF chartなどVisual Studio 2010/.NET Framework 4.0 Beta 1 や、Preview 段階の新しいコントロールを紹介します。
また、WPFの開発パターンとして定着しつつあるM-V-VMパターンについても紹介します。
S2-5 16:00-17:15(75)パネルディスカッション
「レガシー資産をどうされていますか?」
「VB6.0以前をはじめ、.NET Framework 1.0そして1.1もメインサポートが終了、若しくは間もなく終了します。
少し前はVB6.0以前からの移行をご検討されている方が多かったですが、.NET間での以降も視野に入れて行かなければなりません。
皆さんこの辺りをどの様に考えていらっしゃるかディスカッションで討論しませんか。」
【チュートリアルトラック】
T1 13:00-15:45(165)
「オブジェクト指向設計入門」
XPJUG 小井土亨
オブジェクト指向の基本的な考え方からオブジェクト指向設計の基本原則について説明します。また、UMLについても、解説を行います。テキストを使用した例題を解きながら進める予定です。コンピュータは使用しませんが、筆記用具をご用意ください。

posted @ 19:45 | Feedback (0)

2009年6月21日 #

Vs2010 UIのレコーディング

Visual Studio 2010 の 単体テストはUI操作のレコーディングもできる。

まず。テストプロジェクトを追加したのち、コード化されたテストを追加する。

テストの追加

作成オプションでレコーダーの使用を選択する。

テスト2

コード化されたテストレコーダーで操作の記録を開始する。

テスト3

記憶させたい操作を行う。
DatePicker を操作して'2009年6月9日'を選択後'2009年6月26日'を選択。

ちょっと見ずらいが・・・、メソッドを作成ボタンを押す。
テスト4

Public Shared Sub RecordedMethod3(ByVal testContext As TestContext)

    'クリック 'Show Calendar' ボタン
    Dim wpfWindow As WpfWindow = New WpfWindow()
    wpfWindow.SearchProperties.AddRange(New PropertyExpression("Name", "Window1"), New PropertyExpression("ClassName", "HwndWrapper", PropertyExpressionOperator.Contains))
    Dim item2009062600000ComboBox As WpfComboBox = New WpfComboBox(wpfWindow)
    item2009062600000ComboBox.SearchProperties.Add("AutomationId", "DatePicker1")
    Dim showCalendarButton As WpfButton = New WpfButton(item2009062600000ComboBox)
    showCalendarButton.SearchProperties.Add("AutomationId", "PART_Button")
    Mouse.Click(showCalendarButton, New Point(10, 6))

    'クリック '2009年6月9日' ボタン
    Dim item2009062600000Calendar As WpfCalendar = New WpfCalendar(wpfWindow)
    item2009062600000Calendar.SearchProperties.Add("Name", "2009/06/26 0:00:00")
    Dim item2009年6月9日Button As WpfButton = New WpfButton(item2009062600000Calendar)
    item2009年6月9日Button.SearchProperties.Add("Name", "2009年6月9日")
    Mouse.Click(item2009年6月9日Button, New Point(19, 12))

    'クリック 'Show Calendar' ボタン
    Mouse.Click(showCalendarButton, New Point(12, 15))

    'クリック '2009年6月26日' ボタン
    Dim item2009年6月26日Button As WpfButton = New WpfButton(item2009062600000Calendar)
    item2009年6月26日Button.SearchProperties.Add("Name", "2009年6月26日")
    Mouse.Click(item2009年6月26日Button, New Point(6, 8))
End Sub

End Sub の前にテストしたい内容を追加すればテストの作成は完了。

Assert.AreEqual(item2009062600000ComboBox.SelectedItem(), (New DateTime(2009, 6, 26).ToString()))

あとはテストビューからテストするだけです。

posted @ 22:48 | Feedback (3)

2009年6月18日 #

展開の紋章 立方体の展開図のクイズ

立方体を展開図の形にするにはハサミで何回で切ればいいかというクイズがありました。

http://blogs.wankuma.com/izmktr/archive/2009/06/18/175770.aspx
http://blogs.wankuma.com/izmktr/archive/2009/06/17/175694.aspx

ten_basic_old

ten_zure2_old

?ten_kaidan_old

この場合L字型というか270度のところに注目します。
L字型の片側を切るともう片側も切れてしまうので端点になります。
つまり最初の目標としてL字型の真ん中の点同士を結ぶ切り方をすればいいことがわかります。

赤い線を切ると青い線が同時に切れてしまうものとします。
オレンジを切ると水色が同時に切れてしまうものとします。
黄色を切ると黄緑色が同時に切れてしまうものとします。(図の色を黄色と黄緑色と言うとちょっと違和感ありますが)


L字型が2個の3組は赤を切るか青を切るか1組(2種類)の切り方しなく赤と青は交換可能です。従ってこの図で証明されています。
ten_1_1

L字型が3個の4組は最初に切る方法が3種類あります。オレンジと水色は交換可能です。従ってこの3つの図で証明されています。

ten_3_1?
ten_3_2
ten_3_3

L字型が4個の4組は最初に切る方法が4種類あります。
まず、セオリー通りにL時の中央同士が2回切れる方法です。赤とオレンジは交換可能で、黄色と黄緑も交換可能です。

ten_4_1

次に最初に切る場所によって2つ目のL時の中央同士が一部すでに切られていて切れなくなるパターンです。
この場合、オレンジと黄色は交換可能で、オレンジと水色、黄色と黄緑も交換可能です。

ten_4_2

ten_4_3

交換可能なものを含めるとこれで全パターンチェックできたことになります。

posted @ 12:55 | Feedback (0)

2009年6月15日 #

Vs2010 Parallelの中断

Task Parallel Library (TPL) で Parallel を中断するには3つの方法があります。

1つ目は Exception を throw すること、 2つ目は ParallelLoopState クラスの Break メソッドを実行しそれ以上のインデックスが必要ないと宣言すること、3つ目は ParallelLoopState クラスの Stop メソッドを実行ししかかり以外の実行を停止することです。
そして、他の Parallel の実行中にその状態を確認するのが、ParallelLoopState クラスの ShouldExitCurrentIteration プロパティです、個別に IsExceptional や IsStopped や LowestBreakIteration でも確認できます。

尚、Exception を throw すると、 throw された Exception は、全体でまとめられて AggregateException として throw されます、AggregateException の InnerExceptions に全ての Exception は格納されます。

try
{
 Parallel.For(1, 100000, (i, loopState) => {
 // if (i == 20) throw new Exception(“例外");
 // if (i == 20) loopState.Break();
 if (i == 20) loopState.Stop();
 if (loopState.ShouldExitCurrentIteration) return;
 Console.WriteLine(i);
 });
}
catch (AggregateException e) {
 Console.WriteLine(e);
}

posted @ 0:37 | Feedback (0)

2009年6月11日 #

一つの IP で mnow.jp と www.mnow.jp の2つを共存させる

一つの IP で mnow.jp と www.mnow.jp の2つを共存させる必要があったので、やってみました。

DELLSERVER は Windows2003Server で IIS6が動いています。
今までの mnow.jp です。

HPSERVER は Windows2008WebServer で IIS7 が動いています。
将来的には全てWindows2008WebServer に移行するのですが、やはりこちらも外出ししたい。
いや、ほんとは Microsoft スキルチャージプログラム 第3弾 インストールその3 で既に www.mnow.jp で 一回外出ししたのですが、mnow.jp が見えなくなってしまったので内にこもらせたのです。

自宅内ではローカルのネットワーク内で www.mnow.jp と mnow.jp を区別できて表示できるように DNS の設定はされています。

解決方法を探っていくと、リバースプロキシ という単語に突き当りました。
さらに Apache と IIS を共存させるということがわかってきました。

1) Windows 版の Apache を ここから ダウンロードして DELLSERVER(Windows2003Server)にインストール。
2) DELLSERVER の IIS の ポート80 を全て ポート8080 に変更。
3) Apache の httpd.conf の変更。

LoadModule の有効化(コメントはずし)と、NameVirtualHost、VirtualHost の設定です。
ちなみに、hpserver.mnow.local と dellserver.mnow.local は、ローカルのネットワーク内各サーバーのドメイン名です。

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so

NameVirtualHost *:80
<VirtualHost *:80>
  ProxyPass / http://hpserver.mnow.local/
  ProxyPassReverse / http://hpserver.mnow.local/
  ServerName www.mnow.jp
  ErrorLog logs/hpmnow-error.log
</VirtualHost>
<VirtualHost *:80>
  ProxyPass / http://dellserver.mnow.local:8080/
  ProxyPassReverse / http://dellserver.mnow.local:8080/
  ServerName mnow.jp
  ErrorLog logs/mnow-error.log
</VirtualHost>

4) DELLSERVER の IIS や Apache の再起動。
5) DELLSERVER や HPSERVER の DotNetNuke のサイト設定変更
(hpserver.mnow.local/ や dellserver.mnow.local:8080/ を認識させる)

とっちゃん に確認をお願いしながら、特に Apache の httpd.conf は慣れていないので少し試行錯誤で設定しました。
何回も TEST に協力してくれた とっちゃん に感謝です。

もし、Apache の専門家の方が見てくれててここを直したほうがいいよってアドバイスがあれば mnow@yahoo.co.jp にメールください。

ちなみに、Apache のWebページは全くありません。

posted @ 2:34 | Feedback (2)

2009年6月10日 #

自宅環境

でゅあるですぷれいなりー

Mixi ではさらしてたんだけど、Blogでさらしていなかったので見てください。

20081211012625

24インチ 1200x1920 を2台縦置きです。

VisualStudioのソ-スも159文字x119行見れます。
プログラムを確認するときの見通しのいいこと。
もう戻れなくなってしまいそうです。

左でVisualStudioを開いたまま、
右に実行画面を置いたり、ドキュメントを開いたり、
右にTwitterやRSSとかMessengerやSkypeやIRCやメーラなど動く物を置いたり、
なんといってもShadeの正面図・側面図・上面図・透視図を画面いっぱいに広げたときの素晴らしさは圧巻です。

posted @ 1:03 | Feedback (5)

2009年6月9日 #

Mass Effect 終わりました

Mass Effect
http://www.xbox.com/ja-JP/games/splash/m/masseffect/

http://blogs.wankuma.com/mnow/archive/2009/06/02/173974.aspx

結構壮大なスペースロマンでした。

冒険、陰謀、政治の駆け引き、行動の善悪、異星人との恋愛、最後にはXXXを救っちゃうような、ものすごいお話です。
終わった時は結構感動していました。

設定を初心者用にしてやったのでなんとか最後まで行けました。
強い武器を買えるようになってからは結構戦闘も楽でした。

こまめに(自動保存以外に百回ほど)保存していたのでゲームオーバーになってもそんなにロスはなかったので、保存しながら進むといいと思います。

自由度も高くキャラの属性(コンバット・テクノロジー・バイオテック)も変えられるし善悪の選択も可能なので何周も楽しめると思います。

posted @ 13:48 | Feedback (1)

2009年6月8日 #

VS2010 Web と Forms のグラフ表示

SP1は別にインストールしなければいけなかった チャートコントロールです。
http://code.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=1591

VS2010 は標準になっているようです。
http://msdn.microsoft.com/ja-jp/library/system.windows.forms.datavisualization.charting.chart(VS.100).aspx
http://msdn.microsoft.com/ja-jp/library/system.web.ui.datavisualization.charting.chart(VS.100).aspx

こんなチャートが書けます。

メンバー名 説明
Point グラフの種類をポイントします。
FastPoint FastPoint グラフの種類。
Bubble バブル グラフの種類。
Line グラフの種類を行します。
Spline スプラインのグラフの種類。
StepLine StepLine グラフの種類。
FastLine FastLine グラフの種類。
Bar バーのグラフの種類。
StackedBar バーのグラフの種類を並べています。
StackedBar100 100 % 積み上げ横棒グラフの種類。
Column 列のグラフの種類。
StackedColumn 列のグラフの種類を並べています。
StackedColumn100 100 % 積み上げ縦棒グラフの種類。
Area 領域グラフの種類。
SplineArea スプライン エリア グラフの種類。
StackedArea 領域グラフの種類を並べています。
StackedArea100 100 % 積み上げ面グラフの種類。
Pie 円グラフの種類。
Doughnut ドーナツ グラフの種類。
Stock 株価グラフの種類。
Candlestick candlestick グラフの種類。
Range グラフの種類の範囲です。
SplineRange スプライン範囲グラフの種類。
RangeBar RangeBar グラフの種類。
RangeColumn 列のグラフの種類を範囲します。
Radar レーダー グラフの種類。
Polar 極座標グラフの種類。
ErrorBar グラフの種類バー エラーです。
BoxPlot ボックス プロット グラフの種類。
Renko Renko グラフの種類。
ThreeLineBreak ThreeLineBreak グラフの種類。
Kagi Kagi グラフの種類。
PointAndFigure PointAndFigure グラフの種類。
Funnel グラフの種類をフィルタします。
Pyramid グラフの種類をピラミッド型します。

posted @ 2:21 | Feedback (0)

2009年6月7日 #

.NET Framework 4 クラス ライブラリ の新しい名前空間

2つのページを見比べて作成しました。見比べて作ったのでミスがあるかもしれませんが・・・
.NET Framework 3.5 http://msdn.microsoft.com/ja-jp/library/ms229335.aspx
.NET Framework 4  http://msdn.microsoft.com/ja-jp/library/ms229335(VS.100).aspx

どんな名前空間が増えたのか確認できます。(既存名前空間のどんなクラスが増えたかは確認できませんが)
クラス ライブラリ ダイブ の役に立てば光栄です。

 

Microsoft.Build.Construction
Microsoft.Build.Evaluation
Microsoft.Build.Exceptions
Microsoft.Build.Execution
Microsoft.Build.Tasks.ReferenceAssemblyBuild
Microsoft.Build.Tasks.Xaml
System.Activities
System.Activities.Core.Design
System.Activities.Core.Design.Themes
System.Activities.Debugger
System.Activities.Design
System.Activities.Design.Base.PropertyEditing
System.Activities.Design.Core
System.Activities.Design.Debug
System.Activities.Design.Documents
System.Activities.Design.Interaction
System.Activities.Design.Internal.PropertyEditing
System.Activities.Design.Internal.PropertyEditing.Metadata
System.Activities.Design.Metadata
System.Activities.Design.Model
System.Activities.Design.ModelTree
System.Activities.Design.PropertyEditing
System.Activities.Design.Services
System.Activities.Design.Validation
System.Activities.Design.View
System.Activities.Design.Xaml
System.Activities.DynamicUpdate
System.Activities.ExpressionParser
System.Activities.Expressions
System.Activities.Hosting
System.Activities.Persistence
System.Activities.Statements
System.Activities.Tracking
System.Activities.Validation
System.Collections.Concurrent
System.ComponentModel.DataAnnotations
System.Data.Common.CommandTrees
System.Data.Common.CommandTrees.ExpressionBuilder
System.Data.Common.EntitySql
System.Data.Entity.Design
System.Data.Entity.Design.AspNet
System.Data.Entity.Design.PluralizationServices
System.Data.EntityClient
System.Data.Mapping
System.Data.Metadata.Edm
System.Data.Objects
System.Data.Objects.DataClasses
System.Data.Objects.SqlClient
System.Data.Services
System.Data.Services.Client
System.Data.Services.Common
System.Diagnostics.Contracts
System.Dynamic
System.IO.MemoryMappedFiles
System.Management.Automation.Activities
System.Runtime.ExceptionServices
System.Runtime.Persistence
System.Security.Authentication.ExtendedProtection
System.Security.Authentication.ExtendedProtection.Configuration
System.ServiceModel.Activities
System.ServiceModel.Activities.Activation
System.ServiceModel.Activities.Configuration
System.ServiceModel.Activities.Description
System.ServiceModel.Activities.Design
System.ServiceModel.Activities.Dispatcher
System.ServiceModel.Activities.Tracking.Configuration
System.ServiceModel.Discovery
System.ServiceModel.Discovery.Configuration
System.ServiceModel.Routing
System.ServiceModel.Routing.Configuration
System.ServiceModel.Web.Caching
System.Threading.Tasks
System.Web.DynamicData
System.Web.DynamicData.Design
System.Web.DynamicData.ModelProviders
System.Web.UI.DataVisualization.Charting
System.Web.UI.WebControls.Expressions
System.Windows.Baml2006
System.Windows.Forms.DataVisualization.Charting
System.Xaml
System.Xaml.Hosting
System.Xaml.Hosting.Configuration
System.Xaml.Permissions
System.Xaml.Primitives
System.Xaml.Replacements
System.Xaml.Runtime
System.Xaml.Schema
System.Xml.Resolvers

posted @ 11:01 | Feedback (4)

2009年6月2日 #

WPF データーバインディング CoerceValueCallback 問題かも

そんなわけはありません。

と言ってみたけど検証不足でした。

そうかも。

前回は TextBox や Label から Slider への Binding でした。
でも実際使うとしたら Slider から データへの Binding です。

<Window x:Class="BindingTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    Title="Window1" Height="300" Width="300">
    <Grid>
    <Grid.RowDefinitions>
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
    </Grid.RowDefinitions>
    <Slider  Name="slider1" Value="{Binding ElementName=textBox2,Path=Text,diag:PresentationTraceSources.TraceLevel=High}"/>
    <TextBox Grid.Row="1" Name="textBox1" Text="{Binding ElementName=slider1,Path=Value,Mode=TwoWay,diag:PresentationTraceSources.TraceLevel=High}" />
    <Label Grid.Row="2" Name="label1" Content="{Binding ElementName=slider1,Path=Value,diag:PresentationTraceSources.TraceLevel=High}"/>
    <Button Grid.Row="3" Name="button1" Click="button1_Click">Button</Button>
    <TextBox Grid.Row="4" Name="textBox2"/>
  </Grid>
</Window>

slider1 から textBox2 に Binding させてみました。

1)依存関係プロパティーの値を変更 ボタンをクリックすれば slider1.Value =  - 10 となる
System.Windows.Data Warning: 86 : BindingExpression (hash=41014879): Update - got raw value '-10'
System.Windows.Data Warning: 89 : BindingExpression (hash=41014879): Update - implicit converter produced '-10'
System.Windows.Data Warning: 90 : BindingExpression (hash=41014879): Update - using final value '-10'
System.Windows.Data Warning: 98 : BindingExpression (hash=41014879): SetValue at level 0 to TextBox (hash=34340385) using DependencyProperty(Text): '-10'
System.Windows.Data Warning: 92 : BindingExpression (hash=32176063): Got PropertyChanged event from Slider (hash=3888474) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=32176063): GetValue at level 0 from Slider (hash=3888474) using DependencyProperty(Value): '0'
System.Windows.Data Warning: 76 : BindingExpression (hash=32176063): TransferValue - got raw value '0'
System.Windows.Data Warning: 80 : BindingExpression (hash=32176063): TransferValue - implicit converter produced '0'
System.Windows.Data Warning: 85 : BindingExpression (hash=32176063): TransferValue - using final value '0'
System.Windows.Data Warning: 92 : BindingExpression (hash=24123405): Got PropertyChanged event from Slider (hash=3888474) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=24123405): GetValue at level 0 from Slider (hash=3888474) using DependencyProperty(Value): '0'
System.Windows.Data Warning: 76 : BindingExpression (hash=24123405): TransferValue - got raw value '0'
System.Windows.Data Warning: 85 : BindingExpression (hash=24123405): TransferValue - using final value '0'

SetValue at level 0 to TextBox (hash=34340385) using DependencyProperty(Text): '-10' TextBox に ? 10 をセットしています。


2)プロパティーの値を変える TextBox の値を 20 に変更すれば Mode=TwoWay で Slider.Value を変更する
System.Windows.Data Warning: 91 : BindingExpression (hash=32176063): Got LostFocus event from TextBox (hash=44150175)
System.Windows.Data Warning: 86 : BindingExpression (hash=32176063): Update - got raw value '20'
System.Windows.Data Warning: 89 : BindingExpression (hash=32176063): Update - implicit converter produced '20'
System.Windows.Data Warning: 90 : BindingExpression (hash=32176063): Update - using final value '20'
System.Windows.Data Warning: 98 : BindingExpression (hash=32176063): SetValue at level 0 to Slider (hash=3888474) using DependencyProperty(Value): '20'
System.Windows.Data Warning: 86 : BindingExpression (hash=41014879): Update - got raw value '20'
System.Windows.Data Warning: 89 : BindingExpression (hash=41014879): Update - implicit converter produced '20'
System.Windows.Data Warning: 90 : BindingExpression (hash=41014879): Update - using final value '20'
System.Windows.Data Warning: 98 : BindingExpression (hash=41014879): SetValue at level 0 to TextBox (hash=34340385) using DependencyProperty(Text): '20'
System.Windows.Data Warning: 92 : BindingExpression (hash=32176063): Got PropertyChanged event from Slider (hash=3888474) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=32176063): GetValue at level 0 from Slider (hash=3888474) using DependencyProperty(Value): '10'
System.Windows.Data Warning: 76 : BindingExpression (hash=32176063): TransferValue - got raw value '10'
System.Windows.Data Warning: 80 : BindingExpression (hash=32176063): TransferValue - implicit converter produced '10'
System.Windows.Data Warning: 85 : BindingExpression (hash=32176063): TransferValue - using final value '10'
System.Windows.Data Warning: 92 : BindingExpression (hash=24123405): Got PropertyChanged event from Slider (hash=3888474) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=24123405): GetValue at level 0 from Slider (hash=3888474) using DependencyProperty(Value): '10'
System.Windows.Data Warning: 76 : BindingExpression (hash=24123405): TransferValue - got raw value '10'
System.Windows.Data Warning: 85 : BindingExpression (hash=24123405): TransferValue - using final value '10'

SetValue at level 0 to TextBox (hash=34340385) using DependencyProperty(Text): '20' TextBox にやっぱり 20 を入れています。

しかし、問題点として、Slider の CoerceValueCallback のロジックと、textBox2(データソース側)の CoerceValueCallback のロジックが矛盾していたら困るので解決方法はないかも。

データソース側に CoerceValueCallback は通常つけないだろう(DependencyPropertyじゃないのが普通だし)がWPFの場合は両方ともコントロールの場合があるので起こりえるんです。

posted @ 22:42 | Feedback (0)

WPF データーバインディング は大丈夫です

データーバインディングの今後に考えてみた

添付プロパティーとプロパティーとバインドします。
1)添付プロパティーの値を変更→SetValue→プロパティーに値を渡す→CoerceValueCallbackで値が変わるときがある。
結果 添付プロパティーとプロパティーの値が違う
2)プロパティーの値を変える→PropertyChangedCallback→SetValue→CoerceValueCallbackで値が変わるときがある。
結果 添付プロパティーとプロパティーの値が違う

そんなわけはありません。

というわけで調べてみた。

<Window x:Class="BindingTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    Title="Window1" Height="300" Width="300">
    <Grid>
    <Grid.RowDefinitions>
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
    </Grid.RowDefinitions>
    <Slider  Name="slider1" />
    <TextBox Grid.Row="1" Name="textBox1" Text="{Binding ElementName=slider1,Path=Value,Mode=TwoWay,diag:PresentationTraceSources.TraceLevel=High}" />
    <Label Grid.Row="2" Name="label1" Content="{Binding ElementName=slider1,Path=Value,diag:PresentationTraceSources.TraceLevel=High}"/>
    <Button Grid.Row="3" Name="button1" Click="button1_Click">Button</Button>
  </Grid>
</Window>

添付プロパティと依存関係プロパティは強制値コールバックの実装には違いがないので依存関係プロパティで確認してみた。
今回は強制値コールバックを行っている Slider を使った。Slider は Min/Max/Current シナリオ を実装している。規定値はMin=0/Max=10 である。
依存関係プロパティのコールバックと検証

1)依存関係プロパティーの値を変更 ボタンをクリックすれば slider1.Value =  - 10 となる
System.Windows.Data Warning: 92 : BindingExpression (hash=14347911): Got PropertyChanged event from Slider (hash=23264094) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=14347911): GetValue at level 0 from Slider (hash=23264094) using DependencyProperty(Value): '0'
System.Windows.Data Warning: 76 : BindingExpression (hash=14347911): TransferValue - got raw value '0'
System.Windows.Data Warning: 80 : BindingExpression (hash=14347911): TransferValue - implicit converter produced '0'
System.Windows.Data Warning: 85 : BindingExpression (hash=14347911): TransferValue - using final value '0'
System.Windows.Data Warning: 92 : BindingExpression (hash=49584532): Got PropertyChanged event from Slider (hash=23264094) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=49584532): GetValue at level 0 from Slider (hash=23264094) using DependencyProperty(Value): '0'
System.Windows.Data Warning: 76 : BindingExpression (hash=49584532): TransferValue - got raw value '0'
System.Windows.Data Warning: 85 : BindingExpression (hash=49584532): TransferValue - using final value '0'

ちゃんと Binding はMin=0の強制値で伝搬する。

2)プロパティーの値を変える TextBox の値を 20 に変更すれば Mode=TwoWay で Slider.Value を変更する
System.Windows.Data Warning: 91 : BindingExpression (hash=52697953): Got LostFocus event from TextBox (hash=22597652)
System.Windows.Data Warning: 86 : BindingExpression (hash=52697953): Update - got raw value '20'
System.Windows.Data Warning: 89 : BindingExpression (hash=52697953): Update - implicit converter produced '20'
System.Windows.Data Warning: 90 : BindingExpression (hash=52697953): Update - using final value '20'
System.Windows.Data Warning: 98 : BindingExpression (hash=52697953): SetValue at level 0 to Slider (hash=59109011) using DependencyProperty(Value): '20'
System.Windows.Data Warning: 92 : BindingExpression (hash=52697953): Got PropertyChanged event from Slider (hash=59109011) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=52697953): GetValue at level 0 from Slider (hash=59109011) using DependencyProperty(Value): '10'
System.Windows.Data Warning: 76 : BindingExpression (hash=52697953): TransferValue - got raw value '10'
System.Windows.Data Warning: 80 : BindingExpression (hash=52697953): TransferValue - implicit converter produced '10'
System.Windows.Data Warning: 85 : BindingExpression (hash=52697953): TransferValue - using final value '10'
System.Windows.Data Warning: 92 : BindingExpression (hash=40644060): Got PropertyChanged event from Slider (hash=59109011) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=40644060): GetValue at level 0 from Slider (hash=59109011) using DependencyProperty(Value): '10'
System.Windows.Data Warning: 76 : BindingExpression (hash=40644060): TransferValue - got raw value '10'
System.Windows.Data Warning: 85 : BindingExpression (hash=40644060): TransferValue - using final value '10'

TextBox の値を 20 で Slider.Value には伝わるが Got PropertyChanged event from Slider で Binding はMax=10の強制値で伝搬する。

posted @ 12:28 | Feedback (4)

Mass Effect 始めました

Mass Effect
http://www.xbox.com/ja-JP/games/splash/m/masseffect/

RPGと書いてあったのでやっていますが、戦闘はRPGというよりガンシューティングです、展開や会話はアドベンチャーゲームっぽいです、今はダンジョンRPGっぽいので、いろんな要素が入っているんだと思います、キャラクタがソルジャーじゃなければ別の戦い方になるんでしょう。
RPGの次世代を告げるってのはそういう意味なのかもしれないです。

ガンシューティングが大変で最初の時間制限があるミッションで何度もやり直しました、かなりつらい状態です。
設定を初心者用にしてようやく何度目かでコツとルートがつかめてきてなんとか乗り越えました。
車に乗ってのガンシューティングも大変でした、何度も戦闘エリア外に逃げ出しながら回復してやっと越えられました。

その後はあまりガンシューティングで苦労はしていないので、結構なれとコツをつかめばうまくいくのかもしれません。
というかまだ始めたばっかりの状態に近いからかもしれません。

武器は高いです、とてもじゃないけど最初のうちは買えません、しかし拾えたりして買う必要もない気もします。
設定の文章もまとまっていてそれを読んでいるだけでも楽しかったりします。

今何をやるべきかもまとまっているしマップもあるのであまり迷わないで済みそうです。

posted @ 1:04 | Feedback (1)

2009年5月29日 #

WPF の Binding デバッグ機構

WPF の Binding の状態を確認するには WPF の Binding デバッグ機構 を使います。
この機能は .NET Framework Version 3.5 で導入されました。
サポート対象は 3.0SP1 からになっています。

WPF の Binding の Converter が減る方向へ の場合はこのようにします。

<Window x:Class="TextBoxBindings.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TextBoxBindings"
    xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    Title="Window1" Height="107" Width="300">
  <Window.Resources>
    <local:ToUpperConverter x:Key="ToUpperConverter"/>
  </Window.Resources>
  <Window.DataContext>
    <local:Person />
  </Window.DataContext>
  <StackPanel>
    <TextBox Text="{Binding Path=Name, Converter={StaticResource ToUpperConverter}, diag:PresentationTraceSources.TraceLevel=High}" />
    <Button Content="Dummy" />
  </StackPanel>
</Window>

 

以下の文が増えてますね。
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
diag:PresentationTraceSources.TraceLevel=High

 

さっそく Converter なしの確認をします。

System.Windows.Data Warning: 52 : Created BindingExpression (hash=35287174) for Binding (hash=45523402)
System.Windows.Data Warning: 54 :   Path: 'Name'
System.Windows.Data Warning: 56 : BindingExpression (hash=35287174): Default mode resolved to TwoWay
System.Windows.Data Warning: 57 : BindingExpression (hash=35287174): Default update trigger resolved to LostFocus
System.Windows.Data Warning: 58 : BindingExpression (hash=35287174): Attach to System.Windows.Controls.TextBox.Text (hash=44419000)
System.Windows.Data Warning: 63 : BindingExpression (hash=35287174): Resolving source
System.Windows.Data Warning: 66 : BindingExpression (hash=35287174): Found data context element: TextBox (hash=44419000) (OK)
System.Windows.Data Warning: 74 : BindingExpression (hash=35287174): Activate with root item Person (hash=22597652)
System.Windows.Data Warning: 104 : BindingExpression (hash=35287174):   At level 0 - for Person.Name found accessor RuntimePropertyInfo(Name)
System.Windows.Data Warning: 100 : BindingExpression (hash=35287174): Replace item at level 0 with Person (hash=22597652), using accessor RuntimePropertyInfo(Name)
System.Windows.Data Warning: 97 : BindingExpression (hash=35287174): GetValue at level 0 from Person (hash=22597652) using RuntimePropertyInfo(Name): <null>
System.Windows.Data Warning: 76 : BindingExpression (hash=35287174): TransferValue - got raw value <null>
System.Windows.Data Warning: 85 : BindingExpression (hash=35287174): TransferValue - using final value <null>
System.Windows.Data Warning: 91 : BindingExpression (hash=35287174): Got LostFocus event from TextBox (hash=44419000)
System.Windows.Data Warning: 86 : BindingExpression (hash=35287174): Update - got raw value 'aaa'
System.Windows.Data Warning: 90 : BindingExpression (hash=35287174): Update - using final value 'aaa'
System.Windows.Data Warning: 98 : BindingExpression (hash=35287174): SetValue at level 0 to Person (hash=22597652) using RuntimePropertyInfo(Name): 'aaa'
System.Windows.Data Warning: 91 : BindingExpression (hash=35287174): Got PropertyChanged event from Person (hash=22597652)

Got LostFocus event from TextBox に対して反応して SetValue at level 0 to Person (hash=22597652) using RuntimePropertyInfo(Name): 'aaa' があり、Person.Name に aaa が入ります。
しかし、Got PropertyChanged event from Person に対しては無反応です。

 

次に Converter ありの確認をします。
a を一個多めに入れています。

System.Windows.Data Warning: 52 : Created BindingExpression (hash=35287174) for Binding (hash=45523402)
System.Windows.Data Warning: 54 :   Path: 'Name'
System.Windows.Data Warning: 56 : BindingExpression (hash=35287174): Default mode resolved to TwoWay
System.Windows.Data Warning: 57 : BindingExpression (hash=35287174): Default update trigger resolved to LostFocus
System.Windows.Data Warning: 58 : BindingExpression (hash=35287174): Attach to System.Windows.Controls.TextBox.Text (hash=44419000)
System.Windows.Data Warning: 63 : BindingExpression (hash=35287174): Resolving source
System.Windows.Data Warning: 66 : BindingExpression (hash=35287174): Found data context element: TextBox (hash=44419000) (OK)
System.Windows.Data Warning: 74 : BindingExpression (hash=35287174): Activate with root item Person (hash=22597652)
System.Windows.Data Warning: 104 : BindingExpression (hash=35287174):   At level 0 - for Person.Name found accessor RuntimePropertyInfo(Name)
System.Windows.Data Warning: 100 : BindingExpression (hash=35287174): Replace item at level 0 with Person (hash=22597652), using accessor RuntimePropertyInfo(Name)
System.Windows.Data Warning: 97 : BindingExpression (hash=35287174): GetValue at level 0 from Person (hash=22597652) using RuntimePropertyInfo(Name): <null>
System.Windows.Data Warning: 76 : BindingExpression (hash=35287174): TransferValue - got raw value <null>
System.Windows.Data Warning: 78 : BindingExpression (hash=35287174): TransferValue - user's converter produced {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 84 : BindingExpression (hash=35287174): TransferValue - using fallback/default value ''
System.Windows.Data Warning: 85 : BindingExpression (hash=35287174): TransferValue - using final value ''
System.Windows.Data Warning: 91 : BindingExpression (hash=35287174): Got LostFocus event from TextBox (hash=44419000)
System.Windows.Data Warning: 86 : BindingExpression (hash=35287174): Update - got raw value 'aaaa'
System.Windows.Data Warning: 88 : BindingExpression (hash=35287174): Update - user's converter produced 'aaaa'
System.Windows.Data Warning: 90 : BindingExpression (hash=35287174): Update - using final value 'aaaa'
System.Windows.Data Warning: 98 : BindingExpression (hash=35287174): SetValue at level 0 to Person (hash=22597652) using RuntimePropertyInfo(Name): 'aaaa'
System.Windows.Data Warning: 91 : BindingExpression (hash=35287174): Got PropertyChanged event from Person (hash=22597652)
System.Windows.Data Warning: 97 : BindingExpression (hash=35287174): GetValue at level 0 from Person (hash=22597652) using RuntimePropertyInfo(Name): 'AAAA'
System.Windows.Data Warning: 76 : BindingExpression (hash=35287174): TransferValue - got raw value 'AAAA'
System.Windows.Data Warning: 78 : BindingExpression (hash=35287174): TransferValue - user's converter produced 'AAAA'
System.Windows.Data Warning: 85 : BindingExpression (hash=35287174): TransferValue - using final value 'AAAA'

こんどは、Got PropertyChanged event from Person に反応がありました。
GetValue at level 0 from Person (hash=22597652) using RuntimePropertyInfo(Name): 'AAAA' で Person.Name から AAAA を取得して、TransferValue - user's converter で Converter を通して TransferValue - using final value 'AAAA' で TextBox の Text として AAAA を使います。

posted @ 13:57 | Feedback (0)

WPF の Binding の Converter が減る方向へ

Kazuki さんの Blog を補足します。
http://blogs.wankuma.com/kazuki/archive/2009/05/28/173774.aspx

WPF の Binding は TextBox に入力があってフォーカスが離れると property の set を呼びますが、
その時の INotifyPropertyChanged でのイベントには反応しません。

Binding.Converter プロパティ などがセットされていて property の 値と、
表示が変わってくるかもしれない時には INotifyPropertyChanged でのイベントに反応します。

つまり、property の set と TextBox 表示が変わる場合は Converter をつけるのが本来の形なのです。
これによって通常の場合は無駄な INotifyPropertyChanged でのイベントを無視できて処理が削減できるから反応が良くなるというわけです。

以下に例を挙げます。これならVS2008でWPFアプリケーションでも動作します。
今回 Vs2010では いちいち IValueConverter を作らせるのは手間だろうということで Converter をつけなくてもできるように配慮したようです。

using System.ComponentModel;

namespace TextBoxBindings
{
    public class Person : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged メンバ

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
        #endregion

        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                // 名前は大文字なのです
                if (!string.IsNullOrEmpty(_name))
                {
                    _name = _name.ToUpper();
                }
                OnPropertyChanged("Name");
            }
        }
    }
}

using System;
using System.Windows;
using System.Windows.Data;

namespace TextBoxBindings
{
    class ToUpperConverter : IValueConverter
    {
        #region IValueConverter メンバ

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is string)
            {
      //この場合は必要ないが・・・
                return ((string) value).ToUpper();
            }
            return DependencyProperty.UnsetValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }

        #endregion
    }
}

<Window x:Class="TextBoxBindings.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TextBoxBindings"
    Title="Window1" Height="107" Width="300">
  <Window.Resources>
    <local:ToUpperConverter x:Key="ToUpperConverter"/>
  </Window.Resources>
  <Window.DataContext>
    <local:Person />
  </Window.DataContext>
  <StackPanel>
    <TextBox Text="{Binding Path=Name, Converter={StaticResource ToUpperConverter}}" />
    <Button Content="Dummy" />
  </StackPanel>
</Window>

posted @ 0:36 | Feedback (3)

2009年5月28日 #

Vs2010 ちょっとマルチCPU 2

マルチCPUだったら、マルチCPUの分析結果を載せなければCPUメータじゃダメでしょ>俺

class Program
{
    static void Main(string[] args)
    {
        var sw = new Stopwatch();
        sw.Start();
        for (int i=1 ; i<100000 ; i++) for (int j=1 ; j < i ; j++);
        sw.Stop();
        Debug.WriteLine(sw.ElapsedMilliseconds);
        sw.Reset();
        sw.Start();
        Parallel.For(1, 100000, i => { for (int j = 1; j < i; j++);});
        sw.Stop();
        Debug.WriteLine(sw.ElapsedMilliseconds);
    }
}


というわけでマルチCPUの分析結果
1コアのところと4コアのところが一目瞭然。

パラレル

パラレル2

パラレル3

posted @ 20:52 | Feedback (2)

Vs2010 コード追跡のやりやすさ

メソッドの呼び元や呼び先を追跡できる。
call hierarchy

CallHierarchy

プログラムの構成を追跡できる、ifが何個ブロックになっているかなど階層でわかる。
Architecture Explorer

アーキテクチャエクスプローラ

プログラムのメンテしやすさ、ブランチの多さ、階層の深さ、他のクラスへの依存度、プログラム行数を表示してくれる。
Code Metrics Results

コードマトリックス

なんてすばらしいものを用意してくれているんだ。
これだけ用意されたらコード品質の向上をしていかなくてはいけないといいプレーシャーがかかる。

posted @ 14:27 | Feedback (2)

2009年5月27日 #

長いプロパティ名

長いプロパティ名の話題がR・田中一郎のBlogに載っていた。
DataGridViewTextEditBoxColumn
http://blogs.wankuma.com/rti/archive/2009/05/27/173684.aspx

それで長いって?冗談じゃない。


MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 プロパティ
WS-Security 1.0、WS-Trust (2005 年 2 月版)、WS-SecureConversation (2005 年 2 月版)、および WS-SecurityPolicy 1.1 の各セキュリティ仕様に基づく Basic Security Profile 1.0 を必要とするメッセージ セキュリティ バージョンを取得します。

posted @ 21:01 | Feedback (4)

Vs2010 ちょっとマルチCPU

ちょっとマルチCPUをやってみた。

クアッドコアなので時間も約4倍。
パラレルやっているときは4コアとも振り切っている。

12872
3377

メーター

 

class Program
{
    static void Main(string[] args)
    {
        var sw = new Stopwatch();
        sw.Start();
        for (int i=1 ; i<100000 ; i++) for (int j=1 ; j < i ; j++);
        sw.Stop();
        Debug.WriteLine(sw.ElapsedMilliseconds);
        sw.Reset();
        sw.Start();
        Parallel.For(1, 100000, i => { for (int j = 1; j < i; j++);});
        sw.Stop();
        Debug.WriteLine(sw.ElapsedMilliseconds);
    }
}

posted @ 0:05 | Feedback (0)

2009年5月26日 #

Vs2010 WPF ボヨーンボヨーンって感じ

アニメーションは今までは直線かスプライン曲線だったわけだが、Vs2010でばねで弾むような曲線もできる。
ElasticEase EasingMod プロパティ EaseIn/EaseOut/EaseInOut が選択できる。
Springiness でばねの強さ Oscillations で弾む回数が変えられる。

ボヨーンボヨーンって感じになる。

    <Storyboard x:Key="Storyboard2">
        <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
            From="1" To="3.5" Duration="00:00:05">
            <DoubleAnimation.EasingFunction>
                <ElasticEase EasingMode="EaseIn"/>
            </DoubleAnimation.EasingFunction>
        </DoubleAnimation>
        <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
            From="1" To="3.5" Duration="00:00:05">
            <DoubleAnimation.EasingFunction>
                <ElasticEase EasingMode="EaseIn"/>
            </DoubleAnimation.EasingFunction>
        </DoubleAnimation>
    </Storyboard>

posted @ 0:15 | Feedback (0)

2009年5月24日 #

Vs2010 契約という考え方

System.Diagnostics.Contracts 名前空間が存在する。
今までの Debug.Assert から考えて一歩進んだ考え方である。
なんとコンパイル時にワーニングが出てくるのである。
しかもガード句だけではなく戻り値もオブジェクトが利用可能かも契約できる。
http://blogs.msdn.com/somasegar/archive/2009/02/23/devlabs-code-contracts-for-net.aspx

日本語訳
http://ameblo.jp/umesawaa/archive1-200903.html

INFOQ
http://www.infoq.com/jp/news/2009/03/Code-Contracts-Details

こんな使い方をすると思うのだが。
Assert と Assume の区別がわからない。
Ensures や Requires が動いてないように見える。
somasegar Blog の最後の設定画面がないので今回のベータにはある程度しか入っていないんだろう。
(コンパイル時にワーニングが出てくるとか・・・)

こうすれば使えるという情報があったら教えてください。

なにはともあれコード品質の向上にとって楽しみな技術である。

 

~~~~~~~~~~~~~~~

using System;
using System.Diagnostics.Contracts;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Requires1(false);
        }

        static private void Assert1(bool condition)
        {
            Contract.Assert(condition);
        }
        static private void Assert2(bool condition)
        {
            Contract.Assert(condition,"TEST Assert");
        }

        static private void Assume1(bool condition)
        {
            Contract.Assume(condition);
        }
        static private void Assume2(bool condition)
        {
            Contract.Assume(condition, "TEST Assume");
        }

        static private bool Ensures1(bool condition)
        {
            Contract.Ensures(Contract.Result<bool>() != false);
            return condition;
        }
        static private bool Ensures2(bool condition)
        {
            Contract.Ensures(Contract.Result<bool>() != false, "TEST Ensures");
            return condition;
        }

        static private bool EnsuresOnThrow1(bool condition)
        {
            Contract.EnsuresOnThrow<ApplicationException>(Contract.Result<bool>() != false);
            return condition;
        }
        static private bool EnsuresOnThrow2(bool condition)
        {
            Contract.EnsuresOnThrow<ApplicationException>(Contract.Result<bool>() != false, "TEST EnsuresOnThrow");
            return condition;
        }

        static private bool Requires1(bool condition)
        {
            Contract.Requires(condition != false);
            return condition;
        }
        static private bool Requires2(bool condition)
        {
            Contract.Requires(condition != false, "TEST Requires");
            return condition;
        }

        static private bool RequiresAlways1(bool condition)
        {
            Contract.RequiresAlways(condition != false);
            return condition;
        }
        static private bool RequiresAlways2(bool condition)
        {
            Contract.RequiresAlways(condition != false, "TEST RequiresAlways");
            return condition;
        }
    }
}

posted @ 17:45 | Feedback (2)

2009年5月23日 #

依存関係プロパティ を使わない 添付プロパティ

依存関係プロパティ を使わない 添付プロパティ について聞かれましたので確認しました。

添付プロパティは通常は依存関係プロパティとして作成します。
しかし記憶場所を自分で確保すれば依存関係プロパティにする必要はないです。

using System.Collections.Generic;
using System.Windows;

namespace 添付プロパティ
{
    class AttachedPropertyTest1 : UIElement
    {
        public static readonly DependencyProperty TestTextProperty =
            DependencyProperty.RegisterAttached(
            "TestText", typeof (string), typeof (AttachedPropertyTest1));
        public static void SetTestText(DependencyObject element,string text)
        {
            element.SetValue(TestTextProperty,text);
        }
        public static string  GetTestText(DependencyObject element)
        {
            return (string) element.GetValue(TestTextProperty);
        }
    }
    class AttachedPropertyTest2 : UIElement
    {
        private static readonly Dictionary<DependencyObject, object> _list = new Dictionary<DependencyObject, object>();
        public static void SetTestText(DependencyObject element, string text)
        {
            if (_list.ContainsKey(element))
            {
                _list[element] = text;
            }
            else
            {
                _list.Add(element,text);
            }
        }
        public static string GetTestText(DependencyObject element)
        {
            if (_list.ContainsKey(element))
            {
                return (string)_list[element];
            }
            else
            {
                return null;
            }
        }
    }
}

<Window x:Class="添付プロパティ.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:添付プロパティ"
    Title="Window1" Height="300" Width="300">
    <Grid>
    <Grid.RowDefinitions>
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
    </Grid.RowDefinitions>
    <Label Grid.Row="0" local:AttachedPropertyTest1.TestText="aaaaa" Name="Label1">Text1</Label>
    <Label Grid.Row="1" local:AttachedPropertyTest2.TestText="bbbbb" Name="Label2">Text2</Label>
    <Button Grid.Row="2" Name="button1" Click="button1_Click">Button</Button>
  </Grid>
</Window>

private void button1_Click(object sender, RoutedEventArgs e)
{
    Debug.WriteLine("AttachedPropertyTest1/Label1=" + AttachedPropertyTest1.GetTestText(this.Label1));
    Debug.WriteLine("AttachedPropertyTest1/Label2=" + AttachedPropertyTest1.GetTestText(this.Label2));
    Debug.WriteLine("AttachedPropertyTest2/Label1=" + AttachedPropertyTest2.GetTestText(this.Label1));
    Debug.WriteLine("AttachedPropertyTest2/Label2=" + AttachedPropertyTest2.GetTestText(this.Label2));
}

 

AttachedPropertyTest1/Label1=aaaaa
AttachedPropertyTest1/Label2=
AttachedPropertyTest2/Label1=
AttachedPropertyTest2/Label2=bbbbb

 

しかし、以下のHELPのような依存関係プロパティのいいところは使えません。

「DependencyProperty は、型コンバータと、プロパティ値を設定するための XAML 属性構文をサポートします。この属性構文は、Style の Setter、Trigger、または Condition で Property 値を指定するときに使用します。」

Label1

 

ちなみに影響範囲はAttributeでget アクセサに設定します。

[AttachedPropertyBrowsableForChildren()]
添付プロパティの所有者が他の要素の親要素であるときに、その添付プロパティが参照可能になるように指定します。

[AttachedPropertyBrowsableForType(typeof(TextBox))]
複数の型を指定し、その中に一致する型が 1 つでも含まれる場合 (論理 OR)、このプロパティは参照可能です。型にはインターフェイスも指定できます。get アクセサにのみ適用します。

[AttachedPropertyBrowsableWhenAttributePresent()]
AttachedPropertyBrowsableWhenAttributePresentAttribute が適用されているクラスで添付プロパティを参照できるように、クラスでも適用する必要がある .

posted @ 21:13 | Feedback (2)

2009年5月22日 #

.NET ラボ での質問の回答

AJAX非同期呼び出しのイベント周りですが、 PageRequestManager がキーのクラスです。

お決まりの Live Search で調べてもいろいろ情報はあります。
http://search.live.com/results.aspx?q=PageRequestManager&src=IE-SearchBox&Form=IE8SRC

私が調べた2007年04月にはこんなに情報はなかったんですけどね。
ちなみに終了時イベントはこんな感じで拾います。

<script type="text/javascript" language="javascript">
function pageLoad(sender, args) {
 if (!args.get_isPartialLoad()) {
  var prm = Sys.WebForms.PageRequestManager.getInstance();
  prm.add_endRequest(PageRequestManager_OnEndRequest);
 }
}
function PageRequestManager_OnEndRequest(sender, args) {
 if (args.get_error() != null) {
  $get("<% = Label1.ClientID %>").innerHTML = "非同期ポストバックでエラーが発生しました。";
 }
}
</script>

posted @ 2:56 | Feedback (0)