[FIX] made mainwindow MVVM

This commit is contained in:
Sem van der Hoeven
2020-10-20 19:25:56 +02:00
parent f1a47b509d
commit 1552479f4d
2 changed files with 17 additions and 16 deletions

View File

@@ -7,6 +7,8 @@ using System.Windows.Input;
using SharedClientServer;
using System.Diagnostics;
using System.Windows;
using System.Collections.ObjectModel;
using Client.Views;
namespace Client
{
@@ -17,16 +19,12 @@ namespace Client
public ICommand OnHostButtonClick { get; set; }
public ICommand JoinSelectedLobby { get; set; }
public Lobby SelectedLobby { get; set; }
public ViewModel()
{
_model = new Model();
ButtonCommand = new RelayCommand(() =>
{
}, true);
_lobbies = new List<Lobby>();
_lobbies = new ObservableCollection<Lobby>();
_lobbies.Add(new Lobby(50, 3, 8));
_lobbies.Add(new Lobby(69, 1, 9));
@@ -39,9 +37,13 @@ namespace Client
JoinSelectedLobby = new RelayCommand(() =>
{
if (SelectedLobby != null)
{
GameWindow window = new GameWindow();
window.Show();
}
Debug.WriteLine("Joining selected lobby");
});
}, true);
}
private void ClickCheck()
@@ -52,7 +54,6 @@ namespace Client
_model.Numbers = _model.Numbers + 5;
}
public ICommand ButtonCommand { get; set; }
private Model _model;
@@ -69,8 +70,8 @@ namespace Client
}
}
private List<Lobby> _lobbies;
public List<Lobby> Lobbies
private ObservableCollection<Lobby> _lobbies;
public ObservableCollection<Lobby> Lobbies
{
get { return _lobbies; }
set { _lobbies = value; }

View File

@@ -35,7 +35,7 @@
<Label Grid.Row="1" Grid.Column="0" Content="Your username:" FontSize="15" VerticalAlignment="Center"/>
<Label Grid.Row="2" Grid.Column="0" Content="Which color you want to be:" FontSize="15" VerticalAlignment="Center"/>
<Label Grid.Row="2" Grid.Column="0" Content="Select your color:" FontSize="15" VerticalAlignment="Center"/>
<ComboBox Name="colorSelection" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" FontSize="15">
<ComboBoxItem Content="BLUE"/>
<ComboBoxItem Content="RED"/>
@@ -52,7 +52,7 @@
</Grid>
<ListView Name="LobbyList" Grid.Row="1" Grid.Column="0" Margin="10, 10, 10, 10" ItemsSource="{Binding Path=Lobbies}">
<ListView Name="LobbyList" Grid.Row="1" Grid.Column="0" SelectedItem="{Binding SelectedLobby}" Margin="10, 10, 10, 10" ItemsSource="{Binding Path=Lobbies}">
<ListView.View>
<GridView x:Name="grdList">
<GridViewColumn Header="Lobby ID" DisplayMemberBinding="{Binding ID}" Width="70"/>
@@ -67,8 +67,8 @@
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Button Name="joinButton" Grid.Row="0" Content="join a selected lobby" Command="{Binding JoinSelectedLobby}" Width="200" Height="40" HorizontalAlignment="Left" Margin="10, 0, 0, 0"/>
<Button Name="hostButton" Grid.Row="1" Content="host a new lobby" Command="{Binding OnHostButtonClick}" Width="200" Height="40" HorizontalAlignment="left" Margin="10, 0, 0, 0"/>
<Button Name="joinButton" Grid.Row="0" Content="join a selected lobby" Command="{Binding JoinSelectedLobby}" IsEnabled="{Binding Model.CanStartGame}" Width="200" Height="40" HorizontalAlignment="Left" Margin="10, 0, 0, 0"/>
<Button Name="hostButton" Grid.Row="1" Content="host a new lobby" Command="{Binding OnHostButtonClick}" IsEnabled="{Binding Model.CanStartGame}" Width="200" Height="40" HorizontalAlignment="left" Margin="10, 0, 0, 0"/>
</Grid>
</Grid>