Files
29WxOrder/29WxOrderWpf/Ctrls/Statistics/PeriodRevenueStatisticsView.xaml.cs
T
2026-08-07 20:04:53 +08:00

51 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Windows;
using System.Windows.Controls;
using _29WxOrderWpf.Ctrls.Statistics.Models;
using _29WxOrderWpf.Ctrls.Statistics.ViewModels;
namespace _29WxOrderWpf.Ctrls.Statistics
{
/// <summary>
/// 天/周/月周期统计页面(MVVM)。
/// 通过 PeriodType 指定统计周期:Day(天统计)/ Week(周统计)/ Month(月统计)。
/// </summary>
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));
/// <summary>统计周期(Day / Week / Month)</summary>
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);
}
}
}