using System.Windows;
using System.Windows.Controls;
using _29WxOrderWpf.Ctrls.Statistics.Models;
using _29WxOrderWpf.Ctrls.Statistics.ViewModels;
namespace _29WxOrderWpf.Ctrls.Statistics
{
///
/// 天/周/月周期统计页面(MVVM)。
/// 通过 PeriodType 指定统计周期:Day(天统计)/ Week(周统计)/ Month(月统计)。
///
public partial class PeriodRevenueStatisticsView : UserControl
{
public PeriodRevenueStatisticsView()
{
InitializeComponent();
// 默认天统计;当 XAML 指定 Week/Month 时通过 PeriodType 回调切换
DataContext = new PeriodRevenueStatisticsViewModel(PeriodStatisticType.Day);
this.Loaded += PeriodRevenueStatisticsView_Loaded;
}
private void PeriodRevenueStatisticsView_Loaded(object sender, RoutedEventArgs e)
{
//(DataContext as PeriodRevenueStatisticsViewModel).Init();
}
public static readonly DependencyProperty PeriodTypeProperty =
DependencyProperty.Register(
nameof(PeriodType),
typeof(PeriodStatisticType),
typeof(PeriodRevenueStatisticsView),
new PropertyMetadata(PeriodStatisticType.Day, OnPeriodTypeChanged));
/// 统计周期(Day / Week / Month)
public PeriodStatisticType PeriodType
{
get { return (PeriodStatisticType)GetValue(PeriodTypeProperty); }
set { SetValue(PeriodTypeProperty, value); }
}
private static void OnPeriodTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((PeriodRevenueStatisticsView)d).ApplyPeriodType((PeriodStatisticType)e.NewValue);
}
private void ApplyPeriodType(PeriodStatisticType periodType)
{
DataContext = new PeriodRevenueStatisticsViewModel(periodType);
}
}
}