中の技術日誌ブログ

C#とC++/CLIと
VBと.NETとWindowsで戯れる
 

目次

Blog 利用状況

ニュース

自己紹介

東京でソフトウェアエンジニアをやっています。
お仕事大募集中です。
記事執筆や、講師依頼とかでも何でもどうぞ(*^_^*)
似顔絵 MSMVPロゴ
MSMVP Visual C# Since 2004/04-2013/03

記事カテゴリ

書庫

日記カテゴリ

00-整理

01-MSMVP

作っては見たものの利用しないの

http://blogs.wankuma.com/naka/archive/2007/09/18/96638.aspx

2段階バインドをコンバータを通して安全に実現してみる方法

/// 
/// Nullの場合には""を返すコンバータ
///
public class Null許容パラメータConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { //パラメータはstringのみ
string ParameterString = parameter as string; if (ParameterString == null) { return DependencyProperty.UnsetValue; } //valueがNullの場合には空文字列を返す
if (value == null) { return ""; } //Nullでないのでパラメータの文字列の子要素があるかどうかを調べる
Type t = value.GetType(); PropertyInfo pinfo = t.GetProperty(ParameterString); if ( pinfo == null ) { //プロパティ情報が取得できない
return DependencyProperty.UnsetValue; } return pinfo.GetValue(value, null); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return DependencyProperty.UnsetValue; } }

投稿日時 : 2007年9月18日 0:50

コメントを追加

# re: 作っては見たものの利用しないの 2007/09/18 0:51 中博俊

テストもしていない代物

# re: 作っては見たものの利用しないの 2007/09/18 9:14 じゃんぬねっと

これは使わないな...
逆に INullable みたいなのは利用したことあり。

# hJTkLWbXdtxesmAbrL 2013/03/22 22:56 http://crork.com/

e34ATl Thanks again for the post.Much thanks again. Great.

タイトル
名前
URL
コメント