1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| <Window x:Class="D2174215.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:system="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:D2174215"
mc:Ignorable="d"
Title="Scoreboard" Height="450" Width="800">
<Window.Resources>
<ResourceDictionary>
<system:String x:Key="Title">Scoreboard</system:String>
<system:String x:Key="Player_name">Player name:</system:String>
<system:String x:Key="Add_player">Add player</system:String>
<system:String x:Key="Remove">Remove</system:String>
<system:String x:Key="Number_of_players">Number of players:</system:String>
</ResourceDictionary>
</Window.Resources>
<Window.DataContext>
<local:MainViewModel PropertyChanged="MainViewModel_PropertyChanged" />
</Window.DataContext>
<DockPanel>
<TextBlock DockPanel.Dock="Top" Text="{StaticResource ResourceKey=Title}" FontSize="16" FontWeight="Bold" Padding="5" TextAlignment="Center"/>
<Grid DockPanel.Dock="Top" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition MinWidth="150"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{StaticResource ResourceKey=Player_name}" />
<TextBox Grid.Column="1" Text="{Binding PlayerName, UpdateSourceTrigger=PropertyChanged}" x:Name="PlayerName">
<TextBox.InputBindings>
<KeyBinding Key="Return" Command="{Binding AddPlayerCommand}" />
</TextBox.InputBindings>
</TextBox>
<Button Grid.Column="2" Command="{Binding AddPlayerCommand}" Margin="5,0,5,0" Content="{StaticResource ResourceKey=Add_player}">
<Button.InputBindings>
<KeyBinding Key="Return" Command="{Binding AddPlayerCommand}" />
</Button.InputBindings>
</Button>
</Grid>
<StackPanel DockPanel.Dock="Bottom" Margin="10,5,10,10" Orientation="Horizontal">
<TextBlock Text="{StaticResource ResourceKey=Number_of_players}" Margin="0,0,10,0"/>
<TextBlock Text="{Binding Players.Count}"/>
</StackPanel>
<ListView Margin="5" ItemsSource="{Binding Players}">
<d:ListView.ItemsSource>
<x:Array Type="local:Player">
<local:Player Name="Hector"/>
<local:Player Name="Deliah"/>
</x:Array>
</d:ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="20" />
<ColumnDefinition MinWidth="100" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Name}" />
<Button Grid.Column="1"
Content="-"
Command="{Binding DataContext.DecreaseScoreCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
CommandParameter="{Binding}" />
<TextBlock Grid.Column="2" Text="{Binding Score}" TextAlignment="Left" Padding="5" />
<Button Grid.Column="3"
Content="+"
Command="{Binding DataContext.IncreaseScoreCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
CommandParameter="{Binding}" />
<Border Grid.Column="4" />
<Button Grid.Column="5" Margin="10,0,0,0"
Content="{StaticResource ResourceKey=Remove}"
Command="{Binding DataContext.RemovePlayerCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
CommandParameter="{Binding}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DockPanel>
</Window> |
Partager