hh:mm:ss 形式で表示しようとしていますが、常に完全な日付が表示されます。
私のコンバータークラス/依存関係プロパティに何か問題/欠落がありますか? Datetime.now 表示しか表示されません。これを 00:00:00 に変更するにはどうすればよいですか?
私が実際に欲しいのは、初期化として 00:00:00 を表示することです。その後、トラフ タイマーをインクリメントします。
XAML:
<ListBox.ItemTemplate>
<DataTemplate>
DownTime="{Binding DownTime, Converter={StaticResource DateTimeConverter},
ConverterParameter=\{0:hh:mm:ss\}}
</DataTemplate>
</ListBox.ItemTemplate>
依存関係のプロパティ:
public static readonly DependencyProperty DownTimeProperty =
DependencyProperty.Register("DownTime", typeof(DateTime), typeof(RegistrationButton), new UIPropertyMetadata(DateTime.Now));
public DateTime DownTime
{
get { return (DateTime)GetValue(DownTimestandProperty); }
set { SetValue(DownTimeProperty, value); }
}
コンバーター クラス:
[ValueConversion(typeof(DateTime), typeof(String))]
public class DateTimeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
DateTime dt = (DateTime)value;
return dt;
}
// No need to implement converting back on a one-way binding
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string strValue = value as string;
DateTime resultDateTime;
if (DateTime.TryParse(strValue, out resultDateTime))
{
return resultDateTime;
}
return DependencyProperty.UnsetValue;
}
}
ありがとう。