Advertisement
Guest User

MainWindow.xaml.cs

a guest
Nov 21st, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.18 KB | None | 0 0
  1. using System.Windows;
  2. using System.Windows.Controls.Primitives;
  3. using System.Windows.Input;
  4. using System.Windows.Media;
  5. using Microsoft.Win32;
  6. using System.Threading.Tasks;
  7. using MaterialDesignThemes.Wpf;
  8. using MaterialDesignColors;
  9. using System.IO;
  10. using System;
  11. using System.Windows.Media.Effects;
  12. using Game_Launcher.ViewModels;
  13. using Game_Launcher.Views;
  14. using Game_Launcher.Models;
  15.  
  16. namespace Game_Launcher {
  17.     /// <summary>
  18.     /// Interaction logic for MainWindow.xaml
  19.     /// </summary>
  20.  
  21.     //THIS SECTION CURRENTLY NOT WORKING FOR BINDING TO GENRE DROPDOWN
  22.     public partial class MainWindow : Window {
  23.  
  24.         //Have Viewmodels at class level for re-use
  25.         private GridViewModel gridViewModel;
  26.         private PosterViewModel posterViewModel;
  27.         private BannerViewModel bannerViewModel;
  28.         private ListViewModel listViewModel;
  29.  
  30.         public MainWindow() {
  31.             InitializeComponent();
  32.             //refreshGames();  #Commented out to prevent MessageBox until sr is working
  33.  
  34.             //Instantiate new ViewModels ONCE in this constructor
  35.             gridViewModel = new GridViewModel();
  36.             posterViewModel = new PosterViewModel();
  37.             bannerViewModel = new BannerViewModel();
  38.             listViewModel = new ListViewModel();
  39.  
  40.             //Default on start DataContext
  41.             DataContext = listViewModel;
  42.     }
  43.        
  44.  
  45.         private void UIElement_OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
  46.             //until we add StayOpen glag to Drawer this helps with scrollbar
  47.             var dependencyObject = Mouse.Captured as DependencyObject;
  48.             while (dependencyObject != null) {
  49.                 if (dependencyObject is ScrollBar) return;
  50.                 dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
  51.             }
  52.             MenuToggleButton.IsChecked = false;
  53.         }
  54.  
  55.  
  56.         private void RefreshGames_OnClick (object sender, RoutedEventArgs e) {
  57.             refreshGames();
  58.             return;
  59.         }
  60.        
  61.         private void refreshGames() {
  62.             string gameNum;
  63.             string gameFile = "./Resources/GamesList.txt";
  64.             StreamReader sr = new StreamReader(gameFile, true);
  65.             string[] games = File.ReadAllLines(gameFile);
  66.             int numberOfGames = 0;
  67.             string[] columns = new string[0];
  68.  
  69.  
  70.             //Binding attempts
  71.             Games g = new Games();
  72.             g.Title = "Skyrim";
  73.             g.Genres = "Even though this gets assigned to b.Genres it doesn't display";
  74.             g.Path = "A:\\Steam Games\\steamapps\\common\\Skyrim\\SkyrimLauncher.exe";
  75.             g.Link = "https://elderscrolls.bethesda.net/en/skyrim?";
  76.             g.Icon = "A:\\Documents\\Desktop\\imgs\\i-skyrim.png";
  77.             g.Poster = "A:\\Documents\\Desktop\\imgs\\p-skyrim.png";
  78.             g.Banner = "A:\\Documents\\Desktop\\imgs\\b-skyrim.png";
  79.  
  80.             listViewModel.Games = g; //Set the ListViewModel property
  81.  
  82.             //**We dont need this at all**
  83.             ////These SHOULD refresh bindings but don't seem to
  84.             //var dataContext = DataContext;
  85.             //DataContext = null;
  86.             //DataContext = dataContext;
  87.  
  88.             //The strings need to be passed into ListViewModel.cs but not sure how tbh
  89.             columns = games[0].Split('|');
  90.             foreach (var item in games)
  91.             {
  92.                 numberOfGames++;
  93.             }
  94.             //for ()
  95.             //string[,] gamesMulti = new string[numberOfGames, 7];
  96.  
  97.             //gamesMulti = games[0].Split("||");
  98.             //foreach (var item in games) { //this shows a message box for each game
  99.             //    gameNum = games[numberOfGames];
  100.             //    numberOfGames++;
  101.             //    MessageBox.Show(gameNum);
  102.             //}
  103.             //return;
  104.         }
  105.  
  106.         #region Changing display type
  107.  
  108.         //Use class level contexts to change Window DataContext
  109.         private void GridButton_OnClick(object sender, RoutedEventArgs e) {
  110.             DataContext = gridViewModel;
  111.         }
  112.         private void PosterButton_OnClick(object sender, RoutedEventArgs e) {
  113.             DataContext = posterViewModel;
  114.         }
  115.         private void BannerButton_OnClick(object sender, RoutedEventArgs e) {
  116.             DataContext = bannerViewModel;
  117.         }
  118.         private void ListButton_OnClick(object sender, RoutedEventArgs e) {
  119.             DataContext = listViewModel;
  120.         }
  121.         #endregion
  122.         #region Settings
  123.         private void SettingsButton_OnClick(object sender, RoutedEventArgs e) {
  124.             //code needed to bring up a settings form or something idk
  125.             return; //Just a return so the buttons dont error all over your face
  126.         }
  127.         #endregion
  128.  
  129.         AddGameWindow agw = new AddGameWindow();
  130.         private void openAddGameWindow_OnClick(object sender, RoutedEventArgs e) {
  131.             this.Opacity = 0.5;
  132.             agw.ShowDialog();
  133.             this.Opacity = 100;
  134.         }
  135.         protected override void OnClosed(EventArgs e)
  136.         {
  137.             base.OnClosed(e);
  138.             Application.Current.Shutdown();
  139.         }
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement