using MaterialDesignThemes.Wpf;
using Prism.Commands;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TeamAAS_VP.Enums;
namespace TeamAAS_VP.Controls
{
///
/// AddPalletView.xaml 的交互逻辑
///
public partial class AddPalletView : UserControl, INotifyPropertyChanged
{
public AddPalletView()
{
InitializeComponent();
DataContext = this;
}
private int _SelectPageIndex=0;
///
/// Page选择的索引
///
public int SelectPageIndex
{
get { return _SelectPageIndex; }
set { SetProperty(ref _SelectPageIndex, value); }
}
private bool _IsCheckModel1=true;
///
/// Pallet选择的模式(普通托盘)
///
public bool IsCheckModel1
{
get { return _IsCheckModel1; }
set { SetProperty(ref _IsCheckModel1, value); }
}
private bool _IsCheckModel2=false;
///
/// Pallet选择的模式(组合托盘)
///
public bool IsCheckModel2
{
get { return _IsCheckModel2; }
set { SetProperty(ref _IsCheckModel2, value); }
}
private CoordinateModel _CoordinateModel= CoordinateModel.Orthogonality;
///
/// 坐标系模式
///
public CoordinateModel CoordinateModel
{
get { return _CoordinateModel; }
set { SetProperty(ref _CoordinateModel, value); }
}
private bool _Checked1=true;
///
/// 正交坐标系
///
public bool Checked1
{
get { return _Checked1; }
set
{
SetProperty(ref _Checked1, value);
if (value)
{
Checked2 = false;
CoordinateModel = CoordinateModel.Orthogonality;
}
}
}
private bool _Checked2=false;
///
/// 切变坐标系
///
public bool Checked2
{
get { return _Checked2; }
set
{
SetProperty(ref _Checked2, value);
if (value)
{
Checked1 = false;
CoordinateModel = CoordinateModel.Shear;
}
}
}
private string _PalletName;
///
/// 托盘的名称
///
public string PalletName
{
get { return _PalletName; }
set { SetProperty(ref _PalletName, value); }
}
private Visibility _BackButtonVisibility=Visibility.Collapsed;
///
/// 上一步
///
public Visibility BackButtonVisibility
{
get { return _BackButtonVisibility; }
set { SetProperty(ref _BackButtonVisibility, value); }
}
private Visibility _NextButtonVisibility = Visibility.Visible;
///
/// 下一步
///
public Visibility NextButtonVisibility
{
get { return _NextButtonVisibility; }
set { SetProperty(ref _NextButtonVisibility, value); }
}
private Visibility _OKButtonVisibility = Visibility.Collapsed;
///
/// 确定
///
public Visibility OKButtonVisibility
{
get { return _OKButtonVisibility; }
set { SetProperty(ref _OKButtonVisibility, value); }
}
private Visibility _CancelButtonVisibility = Visibility.Visible;
///
/// 取消
///
public Visibility CancelButtonVisibility
{
get { return _CancelButtonVisibility; }
set { SetProperty(ref _CancelButtonVisibility, value); }
}
private DelegateCommand _GoBack;
public DelegateCommand GoBack =>
_GoBack ?? (_GoBack = new DelegateCommand(ExecuteGoBack));
///
/// 上一步
///
void ExecuteGoBack()
{
if (SelectPageIndex == 1)
{
//进入托盘模式选择界面
SelectPageIndex = 0;
BackButtonVisibility = Visibility.Collapsed;
NextButtonVisibility = Visibility.Visible;
OKButtonVisibility = Visibility.Collapsed;
CancelButtonVisibility = Visibility.Visible;
}
else if (SelectPageIndex == 2)
{
if (IsCheckModel1)
{
//进入托盘模式选择界面
SelectPageIndex = 0;
BackButtonVisibility = Visibility.Collapsed;
NextButtonVisibility = Visibility.Visible;
OKButtonVisibility = Visibility.Collapsed;
CancelButtonVisibility = Visibility.Visible;
}
else
{
//进入坐标系模式选择界面
SelectPageIndex = 1;
BackButtonVisibility = Visibility.Visible;
NextButtonVisibility = Visibility.Visible;
OKButtonVisibility = Visibility.Collapsed;
CancelButtonVisibility = Visibility.Visible;
}
}
}
private DelegateCommand _GoNext;
public DelegateCommand GoNext =>
_GoNext ?? (_GoNext = new DelegateCommand(ExecuteGoNext));
///
/// 下一步
///
void ExecuteGoNext()
{
if (SelectPageIndex==0)
{
if (IsCheckModel1)
{
//进入输入名称界面
SelectPageIndex = 2;
BackButtonVisibility= Visibility.Visible;
NextButtonVisibility= Visibility.Collapsed;
OKButtonVisibility = Visibility.Visible;
CancelButtonVisibility = Visibility.Visible;
}
else
{
//进入坐标系模式选择界面
SelectPageIndex = 1;
BackButtonVisibility = Visibility.Visible;
NextButtonVisibility = Visibility.Visible;
OKButtonVisibility = Visibility.Collapsed;
CancelButtonVisibility = Visibility.Visible;
}
}
else if (SelectPageIndex == 1)
{
//进入输入名称界面
SelectPageIndex = 2;
BackButtonVisibility = Visibility.Visible;
NextButtonVisibility = Visibility.Collapsed;
OKButtonVisibility = Visibility.Visible;
CancelButtonVisibility = Visibility.Visible;
}
}
#region 属性通知
///
/// Occurs when a property value changes.
///
public event PropertyChangedEventHandler PropertyChanged;
///
/// Checks if a property already matches a desired value. Sets the property and
/// notifies listeners only when necessary.
///
/// Type of the property.
/// Reference to a property with both getter and setter.
/// Desired value for the property.
/// Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers that
/// support CallerMemberName.
/// True if the value was changed, false if the existing value matched the
/// desired value.
protected virtual bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer.Default.Equals(storage, value)) return false;
storage = value;
RaisePropertyChanged(propertyName);
return true;
}
///
/// Checks if a property already matches a desired value. Sets the property and
/// notifies listeners only when necessary.
///
/// Type of the property.
/// Reference to a property with both getter and setter.
/// Desired value for the property.
/// Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers that
/// support CallerMemberName.
/// Action that is called after the property value has been changed.
/// True if the value was changed, false if the existing value matched the
/// desired value.
protected virtual bool SetProperty(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer.Default.Equals(storage, value)) return false;
storage = value;
onChanged?.Invoke();
RaisePropertyChanged(propertyName);
return true;
}
///
/// Raises this object's PropertyChanged event.
///
/// Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers
/// that support .
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
///
/// Raises this object's PropertyChanged event.
///
/// The PropertyChangedEventArgs
protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
{
PropertyChanged?.Invoke(this, args);
}
#endregion
}
}