ビューのイメージソースのビューモデルクラスから文字列プロパティをバインドします。 Stringプロパティは、男性の場合は1、女性の場合は2になります。私は画像ソースのuriを返すバインディングにもconverterを使用しています。ビューでイメージ変換元の変換なしの値変換器
私はこれを持っている:
<Image Style="{StaticResource InfoIcon}"
Source="{Binding ., Mode=OneWay,UpdateSourceTrigger=PropertyChanged,
Converter={StaticResource sexImgConverter},
ConverterParameter=Oponent.Info.Sex}"/>
変換方法はこちらです:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
const string woman = "/images/icons/chat/woman.png";
const string man = "/images/icons/chat/man.png";
string result = string.Empty;
string result = int.Parse(value.ToString()) == 1 ? man : woman;
return new Uri(result);
}
問題は、私は文字列型である(ビューOponent.Info.Sex中)プロパティセックスを結合して、解析されます整数にする。
しかし、私はライン上debugerブレークポイントを追加した場合:
string resul = int.Parse(value.ToString()) == 1 ? man : woman;
私はその価値が私の見解モデルクラスのタイプである参照してください。
私は、この変換方法に無い別のバインドを使用してみてください、ここにある:
<TextBlock Style="{StaticResource InfoText}">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1} rokov">
<Binding Path="Oponent.Info.Sex" Converter="{StaticResource sexConverter}"/>
<Binding Path= "Oponent.Info.Age"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
私は同じ最速を使用するライン上のdebugerブレークポイントを追加します。
string resul = int.Parse(value.ToString()) == 1 ? man : woman;
私は価値がある見ます文字列のタイプ。
どうしたのですか?
ありがとう、今私は理解しています:) –