0

I'm making a games launcher for the games myself and my teammates have made in Game Jams, the aim is to have to launcher as below if possible. Each game showing as a tile, ideally as a UserControl so we can set different behaviours when the user mouse's over them and selects them. The overall idea being that we can just update a .xml file to add new games to the launcher (As well as the game files).

Below Image is a design image, not the app while running enter image description here

However, I'm struggling to get anything to display when the launcher loads. Its loading the game data from a file into a ObservableCollection in the windows ViewModel but the UserControls don't seem to be displaying anything regardless of if they're set in a UserControl or just set into the ListView template. Codes Below:

MainWindow.xaml

<Window x:Class="LPG_Launcher.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:LPG_Launcher" xmlns:systemviews="clr-namespace:LPG_Launcher.SystemViews"
        mc:Ignorable="d"
        WindowStyle="None"
        ResizeMode="NoResize"
        Title="LowPoly Games Launcher" Height="800" Width="1200">
    <Grid>
        <Grid.Background>
            <LinearGradientBrush StartPoint="0, 1" EndPoint="1, 0">
                <LinearGradientBrush.GradientStops>
                    <GradientStop Color="#292933" Offset="0.0" />
                    <GradientStop Color="#272732" Offset="0.05" />
                    <GradientStop Color="#242532" Offset="0.1" />
                    <GradientStop Color="#222331" Offset="0.15" />
                    <GradientStop Color="#202131" Offset="0.2" />
                    <GradientStop Color="#1E1F30" Offset="0.25" />
                    <GradientStop Color="#1B1D2F" Offset="0.3" />
                    <GradientStop Color="#191B2F" Offset="0.35" />
                    <GradientStop Color="#17192E" Offset="0.4" />
                    <GradientStop Color="#14172E" Offset="0.45" />
                    <GradientStop Color="#12152D" Offset="0.5" />
                    <GradientStop Color="#14172E" Offset="0.55" />
                    <GradientStop Color="#17192E" Offset="0.6" />
                    <GradientStop Color="#191B2F" Offset="0.65" />
                    <GradientStop Color="#1B1D2F" Offset="0.7" />
                    <GradientStop Color="#1E1F30" Offset="0.75" />
                    <GradientStop Color="#202131" Offset="0.8" />
                    <GradientStop Color="#222331" Offset="0.85" />
                    <GradientStop Color="#242532" Offset="0.9" />
                    <GradientStop Color="#272732" Offset="0.95" />
                    <GradientStop Color="#292933" Offset="1.0" />
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <systemviews:TitleBar Grid.Row="0" />
        <systemviews:GamesList Grid.Row="1" />
    </Grid>
</Window>

MainWindowViewModel - This is being set as the DataContext in MainWindow.xaml.cs

    class MainWindowViewModel
    {
        private GameStorage gameData; //Contains a public ObservableCollection<Game> Games

        public MainWindowViewModel()
        {
            gameData = new GameStorage();
        }
    }

GamesList.xaml

<UserControl x:Class="LPG_Launcher.SystemViews.GamesList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:LPG_Launcher.SystemViews"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <TextBlock Grid.Column="0" Margin="50 25 25 0" VerticalAlignment="Center" Foreground="White" FontSize="48" FontFamily="Bebas Neue Bold" Text="Library" />
        <ListView Margin="0,25,0,-125" Grid.Row="1" ItemsSource="{Binding Path=gameData.Games}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <WrapPanel>
                        <!--<local:Game />-->
                        <TextBlock Text="{Binding Path=Name}" />
                    </WrapPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</UserControl>

If there is a better alternative to this then please do let me know.

Istalri Skolir
  • 96
  • 1
  • 11
  • 2
    Data binding works with public properties, but not with fields like `gameData`. Besides that, you may want to use a WrapPanel or UniformGrid in the `ItemsPanel` of the ListBox. And since you are apparently not utilizing the selection feature of the ListBox, you may want to use an ItemsControl instead. – Clemens May 28 '22 at 13:36
  • Thank you, so I'm guessing the binding needs to be directely with Games which is the ObservableCollection instead of gameData.Games? I'll also look into the wrappanel/uniformgrid of the ItemsPanel. – Istalri Skolir May 28 '22 at 13:39
  • 1
    Declare `public GameStorage GameData { get; } = new GameData();` and `ItemsSource="{Binding GameData.Games}"`. – Clemens May 28 '22 at 14:41

0 Answers0