using SourceChord.FluentWPF;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
namespace Phihong_EVSE_UI_Tool
{
///
/// MainWindow.xaml 的互動邏輯
///
public partial class MainWindow : Window
{
private Properties.Settings mySettings = Properties.Settings.Default;
private ListViewItem lastSelectedItem = null;
private InitialIdleUC ucInitialIdle = new InitialIdleUC();
private AuthenticationUC ucAuthentaction = new AuthenticationUC();
private PlugChargingUC ucPlugCharging = new PlugChargingUC();
private MaintenanceUC ucMaintenance = new MaintenanceUC();
private BuildIco ucBuildIco = new BuildIco();
private ModifyIco ucModifyIco = new ModifyIco();
private SaveSdCard ucSaveSdCard = new SaveSdCard();
public MainWindow()
{
InitializeComponent();
//this.MaxHeight = SystemParameters.WorkArea.Height + 12.5;
this.MinWidth = 900;
this.MinHeight = 600;
uxInitListViewItem.IsSelected = true;
uxInitListViewItem.Focus();
if (!mySettings.Mode.Equals("54088"))
{
uxBuildListViewItem.Visibility = Visibility.Collapsed;
uxSaveMenuTextBlock.Margin = new Thickness(17, 433, 0, 0);
}
Utility.ChangedFiles = Utility.ChangedFiles.ToDictionary(p => p.Key, p => false);
}
private void uxMenuListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (uxMenuListView.SelectedItem != null)
{
if (lastSelectedItem != null)
{
lastSelectedItem.Foreground = new SolidColorBrush(Colors.Black);
lastSelectedItem.Background = null;
}
ListViewItem item = uxMenuListView.SelectedItem as ListViewItem;
Binding myBinding = new Binding("ImmersiveSystemAccentBrush");
myBinding.Source = new AccentColors();
item.SetBinding(ListViewItem.ForegroundProperty, myBinding);
item.Background = new SolidColorBrush(Color.FromArgb(40, 0, 0, 0));
uxTitleTextBlock.Text = (item.Content as StackPanel).Children.OfType().First().Text;
uxContentGrid.Children.Clear();
switch (item.Name)
{
case "uxInitListViewItem":
uxContentGrid.Children.Add(ucInitialIdle);
uxContentGrid.Children.OfType().First().uxContentScrollViewer.ScrollToTop();
break;
case "uxAuthListViewItem":
uxContentGrid.Children.Add(ucAuthentaction);
uxContentGrid.Children.OfType().First().uxContentScrollViewer.ScrollToTop();
break;
case "uxChargingListViewItem":
uxContentGrid.Children.Add(ucPlugCharging);
uxContentGrid.Children.OfType().First().uxContentScrollViewer.ScrollToTop();
break;
case "uxMaintainListViewItem":
uxContentGrid.Children.Add(ucMaintenance);
uxContentGrid.Children.OfType().First().uxContentScrollViewer.ScrollToTop();
break;
case "uxBuildListViewItem":
uxContentGrid.Children.Add(ucBuildIco);
uxContentGrid.Children.OfType().First().uxContentScrollViewer.ScrollToTop();
break;
case "uxModifyListViewItem":
uxContentGrid.Children.Add(ucModifyIco);
uxContentGrid.Children.OfType().First().uxContentScrollViewer.ScrollToTop();
break;
case "uxSaveListViewItem":
uxContentGrid.Children.Add(ucSaveSdCard);
uxContentGrid.Children.OfType().First().uxContentScrollViewer.ScrollToTop();
break;
default:
break;
}
lastSelectedItem = item;
}
}
}
public class DpiDecorator : Decorator
{
public DpiDecorator()
{
this.Loaded += (s, e) =>
{
Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
ScaleTransform dpiTransform = new ScaleTransform(1.25 / m.M11, 1.25 / m.M22);
if (dpiTransform.CanFreeze)
{
dpiTransform.Freeze();
}
this.LayoutTransform = dpiTransform;
};
}
}
}