MVVMを使い始めてINotifyPropertyChangedを実装することができました。次の問題に直面しています。私のdatepickerの月をクエリに渡しても、私が別の月を選択すると、私のクエリは変わらない。twoWayバインディングがdatepickerで動作しないMVVM
私はINotifyPropertyChangedがそれを処理することを望んでいました。 datepickerとは別の月を選択するときに効率性がどのように変化するか確認するにはどうすればよいですか?
はあなたに
のViewModel
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Location.Model;
using System.Windows.Controls;
namespace Location.ViewModel
{
public class LocationViewModel: INotifyPropertyChanged
{
public LocationViewModel()
{
var month = 0;
int.TryParse(MDate.ToString("MM"), out month);
var db = new DailyEntities();
Efficiency = Convert.ToDecimal(db.LocationKPI.Where(a => a.sMonth == month).Select(a => a.Efficiency).FirstOrDefault());
}
private DateTime _mDate = DateTime.Now;
public DateTime MDate
{
get { return _mDate; }
set { _mDate = value; OnPropertyChanged("MDate"); }
}
decimal efficiency;
public decimal Efficiency
{
get { return efficiency; }
set
{
efficiency = value;
OnPropertyChanged("Efficiency");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
ビュー
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new LocationViewModel();
}
}
XAML
ありがとうございました210
あなたはMVVMアプリの背後にあるコードがありますか? 'SelectedDateChanged =" vDatePick_SelectedDateChanged "' –
あなたは正しいです、それは本当に悪い習慣です。私はMVVMに移行し始めましたが、残念です。 – iCosmin