Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Windows;
- using System.Windows.Controls.Primitives;
- using System.Windows.Input;
- using System.Windows.Media;
- using Microsoft.Win32;
- using System.Threading.Tasks;
- using MaterialDesignThemes.Wpf;
- using MaterialDesignColors;
- using System.IO;
- using System;
- using System.Windows.Media.Effects;
- using Game_Launcher.ViewModels;
- using Game_Launcher.Views;
- using Game_Launcher.Models;
- namespace Game_Launcher {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- //THIS SECTION CURRENTLY NOT WORKING FOR BINDING TO GENRE DROPDOWN
- public partial class MainWindow : Window {
- //Have Viewmodels at class level for re-use
- private GridViewModel gridViewModel;
- private PosterViewModel posterViewModel;
- private BannerViewModel bannerViewModel;
- private ListViewModel listViewModel;
- public MainWindow() {
- InitializeComponent();
- //refreshGames(); #Commented out to prevent MessageBox until sr is working
- //Instantiate new ViewModels ONCE in this constructor
- gridViewModel = new GridViewModel();
- posterViewModel = new PosterViewModel();
- bannerViewModel = new BannerViewModel();
- listViewModel = new ListViewModel();
- //Default on start DataContext
- DataContext = listViewModel;
- }
- private void UIElement_OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
- //until we add StayOpen glag to Drawer this helps with scrollbar
- var dependencyObject = Mouse.Captured as DependencyObject;
- while (dependencyObject != null) {
- if (dependencyObject is ScrollBar) return;
- dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
- }
- MenuToggleButton.IsChecked = false;
- }
- private void RefreshGames_OnClick (object sender, RoutedEventArgs e) {
- refreshGames();
- return;
- }
- private void refreshGames() {
- string gameNum;
- string gameFile = "./Resources/GamesList.txt";
- StreamReader sr = new StreamReader(gameFile, true);
- string[] games = File.ReadAllLines(gameFile);
- int numberOfGames = 0;
- string[] columns = new string[0];
- //Binding attempts
- Games g = new Games();
- g.Title = "Skyrim";
- g.Genres = "Even though this gets assigned to b.Genres it doesn't display";
- g.Path = "A:\\Steam Games\\steamapps\\common\\Skyrim\\SkyrimLauncher.exe";
- g.Link = "https://elderscrolls.bethesda.net/en/skyrim?";
- g.Icon = "A:\\Documents\\Desktop\\imgs\\i-skyrim.png";
- g.Poster = "A:\\Documents\\Desktop\\imgs\\p-skyrim.png";
- g.Banner = "A:\\Documents\\Desktop\\imgs\\b-skyrim.png";
- listViewModel.Games = g; //Set the ListViewModel property
- //**We dont need this at all**
- ////These SHOULD refresh bindings but don't seem to
- //var dataContext = DataContext;
- //DataContext = null;
- //DataContext = dataContext;
- //The strings need to be passed into ListViewModel.cs but not sure how tbh
- columns = games[0].Split('|');
- foreach (var item in games)
- {
- numberOfGames++;
- }
- //for ()
- //string[,] gamesMulti = new string[numberOfGames, 7];
- //gamesMulti = games[0].Split("||");
- //foreach (var item in games) { //this shows a message box for each game
- // gameNum = games[numberOfGames];
- // numberOfGames++;
- // MessageBox.Show(gameNum);
- //}
- //return;
- }
- #region Changing display type
- //Use class level contexts to change Window DataContext
- private void GridButton_OnClick(object sender, RoutedEventArgs e) {
- DataContext = gridViewModel;
- }
- private void PosterButton_OnClick(object sender, RoutedEventArgs e) {
- DataContext = posterViewModel;
- }
- private void BannerButton_OnClick(object sender, RoutedEventArgs e) {
- DataContext = bannerViewModel;
- }
- private void ListButton_OnClick(object sender, RoutedEventArgs e) {
- DataContext = listViewModel;
- }
- #endregion
- #region Settings
- private void SettingsButton_OnClick(object sender, RoutedEventArgs e) {
- //code needed to bring up a settings form or something idk
- return; //Just a return so the buttons dont error all over your face
- }
- #endregion
- AddGameWindow agw = new AddGameWindow();
- private void openAddGameWindow_OnClick(object sender, RoutedEventArgs e) {
- this.Opacity = 0.5;
- agw.ShowDialog();
- this.Opacity = 100;
- }
- protected override void OnClosed(EventArgs e)
- {
- base.OnClosed(e);
- Application.Current.Shutdown();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement