TimePicker.SelectedTimeChanged 事件

定义

SelectedTime 属性的值更改后发生。

// Register
event_token SelectedTimeChanged(TypedEventHandler<TimePicker, TimePickerSelectedValueChangedEventArgs const&> const& handler) const;

// Revoke with event_token
void SelectedTimeChanged(event_token const* cookie) const;

// Revoke with event_revoker
TimePicker::SelectedTimeChanged_revoker SelectedTimeChanged(auto_revoke_t, TypedEventHandler<TimePicker, TimePickerSelectedValueChangedEventArgs const&> const& handler) const;
public event TypedEventHandler<TimePicker,TimePickerSelectedValueChangedEventArgs> SelectedTimeChanged;
function onSelectedTimeChanged(eventArgs) { /* Your code */ }
timePicker.addEventListener("selectedtimechanged", onSelectedTimeChanged);
timePicker.removeEventListener("selectedtimechanged", onSelectedTimeChanged);
- or -
timePicker.onselectedtimechanged = onSelectedTimeChanged;
Public Custom Event SelectedTimeChanged As TypedEventHandler(Of TimePicker, TimePickerSelectedValueChangedEventArgs) 
<TimePicker SelectedTimeChanged="eventhandler" />

事件类型

Windows 要求

设备系列
Windows 10, version 1809 (在 10.0.17763.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v7.0 中引入)

示例

有关结合使用 DatePickerTimePicker 来更新单个 DateTime 值的示例,请查看日历、日期和时间控件 - 将日期选取器和时间选取器结合使用

<TimePicker SelectedTimeChanged="TimePicker_SelectedTimeChanged"/>
<TextBlock x:Name="resultText"/>
private void TimePicker_SelectedTimeChanged(TimePicker sender, TimePickerSelectedValueChangedEventArgs args)
{
    DateTime myTime = DateTime.Today + (TimeSpan)args.NewTime;
    if (DateTime.Now >= myTime)
    {
        resultText.Text = "Your selected time has already past.";
    }
    else
    {
        string hrs = (myTime - DateTime.Now).Hours.ToString();
        string mins = (myTime - DateTime.Now).Minutes.ToString();
        resultText.Text = string.Format("Your selected time is {0} hours, {1} minutes from now.", hrs, mins);
    }
}

适用于