データバインディング時に表示される文字列のフォーマットに問題があるだけです。
プロパティサイズがあるとします:
/// <summary>
/// Size information
/// </summary>
private long _size;
public long Size
{
get
{
return _size;
}
set
{
if (value != _size)
{
_size = value;
NotifyPropertyChanged("Size");
}
}
}
このサイズは、バイト数を表す整数です。整数の大きさに応じてサイズを表す値を表示したい。例えば:
Size = 1 byte
Size = 1 kilobyte
Size = 100 megabytes
TextBlock の XAML は次のとおりです。
<TextBlock Text="{Binding Size, StringFormat='Size: {0}'}" TextWrapping="Wrap" Margin="12,110,0,0" Style="{StaticResource PhoneTextSubtleStyle}" Visibility="{Binding Visible}" FontSize="14" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="200"/>
現時点では、50バイトを意味する「サイズ:50」と表示されていますが、「サイズ:50バイト/キロバイト/メガバイト」(適切なもののいずれか)を表示したいのですが、そうでない場合は「サイズ:50000000000000」と巨大になりますそんな数字。
文字列形式を「動的に」変更するにはどうすればよいですか?
テキストブロックは、ObservableCollection で囲まれた LongListSelector 内に含まれていることに注意してください。テキストブロックの形式を使用するオブジェクトのヒープがあるため、テキストブロックを取得してテキストを変更するだけでは機能しません。
ありがとう。