converter コードスニペット
#wp7dev_jp
バインドを扱う上で Convereterは便利なクラス。定型なのに、簡単に入力できないのでスニペットにしてみました。
public class MyValueConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
string formatString = parameter as string;
if (!string.IsNullOrEmpty(formatString))
{
return string.Format(culture, formatString, value);
}
return value.ToString();
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
サンプルは入っていますが、参考にして作ればOK。
マイ ドキュメントのVisual Studio 2010\Code Snippets\Visual C#\My Code Snippets に置けばOK。
使うときは conv [tab] [tab] で使えます。