【发布时间】:2017-12-02 21:08:28
【问题描述】:
我需要在日期更改时更新 wpf listview。我已经编写了在单击按钮时更新列表视图的方法。使用 INotifyPropertyChanged 在日期更改时触发相同的按钮。我有以下代码,但需要帮助才能单击相同的按钮或任何其他方法。
这是需要点击的wpf按钮。
<Button x:Name="SearchButton" Content="Search" HorizontalAlignment="Left"
Margin="344,161,0,0" VerticalAlignment="Top" Click="SearchButton_Click"
FontSize="18" FontWeight="Bold" />
public MainPage()
{
this.InitializeComponent();
this.DataContext = clock;
clock.InitClock(); //using another INotifyPropertyChanged to update clock on textbox
cDate.dateInitClock();
}
public class ChangeDate : INotifyPropertyChanged
{
DispatcherTimer dateTimer = new DispatcherTimer();
public string _date { get; set; }
public string Date
{
get { return _date; }
set
{
_date = value;
OnPropertyChanged("Date");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string date)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(date));
}
}
public void dateInitClock()
{
dateTimer.Tick += dateTimer_Tick;
dateTimer.Interval = new TimeSpan(0, 0, 1, 0);
dateTimer.Start();
}
private void dateTimer_Tick(object sender, object e)
{
// do we need to add action here?
}
}
【问题讨论】:
-
你不点击(事件)你执行了一个命令(
Command={Binding YourCommand) -
你能帮我在按钮中添加什么命令吗?
-
完成,请看下面的答案
标签: c# wpf inotifypropertychanged