The ViewModel
No edit summary
No edit summary
Line 39: Line 39:
         ScheduledDate = DateTime.Now
         ScheduledDate = DateTime.Now
     };
     };
Code Snippet
<Window x:Class="WPFBinding.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:eco="clr-namespace:Eco.WPF;assembly=Eco.WPF"
    xmlns:ecoVM="clr-namespace:Eco.ViewModel.WPF;assembly=Eco.WPF"
    xmlns:Controls="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    xmlns:local="clr-namespace:WPFBinding"
    xmlns:ecospace="clr-namespace:WPFBinding;assembly=WPFBinding.EcoSpace"
    Title="Window2" Height="300" Width="500" >
    <Window.Resources>
        <ecoVM:ViewModelContent x:Key="VM1" ViewModelName="GameSetup" EcoSpaceType="{x:Type ecospace:WPFBindingEcoSpace}" ></ecoVM:ViewModelContent>
        <local:ImageBlobConverter x:Key="ImageBlobConverter"/>
    </Window.Resources>
    <Grid>
        <Grid Name="vmrootStackPanel" DataContext="{StaticResource VM1}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="50"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" Grid.Column="0" Text="GAME : " HorizontalAlignment="Right" ></TextBlock>
            <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding  Path=Class[GameSetup]/Presentation,Mode=OneWay}"></TextBox>
            <TextBlock Grid.Row="1" Grid.Column="0" Text="Type of game : " HorizontalAlignment="Right" ></TextBlock>
            <ComboBox Grid.Row="1" Grid.Column="1"  DisplayMemberPath="Name"  ItemsSource="{Binding Path=Class[GameType_PickListPresentation]}" SelectedValuePath="self"  SelectedValue="{Binding Path=Class[GameSetup]/GameType}"  ></ComboBox>
            <TextBlock Grid.Row="2" Grid.Column="0" Text="Home team : " HorizontalAlignment="Right" ></TextBlock>
            <ComboBox Grid.Row="2" Grid.Column="1"  DisplayMemberPath="Name"  ItemsSource="{Binding Path=Class[Home_PickListPresentation]}" SelectedValuePath="self"  SelectedValue="{Binding Path=Class[GameSetup]/Home}"></ComboBox>
            <Image Grid.Row="2" Grid.Column="2"  Source="{Binding Path=Class[GameSetup]/Home_Image,Mode=OneWay,Converter={StaticResource ImageBlobConverter} }"></Image>
            <TextBlock Grid.Row="3" Grid.Column="0" Text="Visitor team : " HorizontalAlignment="Right" ></TextBlock>
            <ComboBox Grid.Row="3" Grid.Column="1"  DisplayMemberPath="Name"  ItemsSource="{Binding Path=Class[Visitor_PickListPresentation]}" SelectedValuePath="self"  SelectedValue="{Binding Path=Class[GameSetup]/Visitor}"></ComboBox>
            <Image Grid.Row="3" Grid.Column="2"  Source="{Binding Path=Class[GameSetup]/Visitor_Image,Mode=OneWay,Converter={StaticResource ImageBlobConverter} }"></Image>
            <TextBlock Grid.Row="4" Grid.Column="0" Text="Scheduled date : " HorizontalAlignment="Right" ></TextBlock>
            <Controls:DatePicker Grid.Row="4" Grid.Column="1"  ></Controls:DatePicker>
            <Button Grid.Row="5" Grid.Column="0" IsEnabled="{Binding Path=Class[GameSetup]/CanStartGame}" Click="ButtonStartGame_Click">
                <TextBlock Text="Start Game"></TextBlock>
            </Button>
            <Button  Grid.Row="5" Grid.Column="1"  IsEnabled="{Binding Path=Class[GameSetup]/CanEndGame}" >
                <TextBlock Text="End Game" ></TextBlock>
            </Button>
        </Grid>
        <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom">
            <Image Height="50" Name="imagebrynäs" Stretch="Fill" Width="50" Source="/WPFBinding;component/brynäs.jpg" />
            <Image Height="50" Name="imagedjurgården" Stretch="Fill" Width="50" Source="/WPFBinding;component/djurgården.jpg" />
            <Image Height="50" Name="imageluleå" Stretch="Fill" Width="50" Source="/WPFBinding;component/Luleå.jpg" />
        </StackPanel>
    </Grid>
</Window>

Revision as of 15:02, 24 October 2018

private Game CreateSomeTestData() {

   // Game types
   var gtboys15 = new GameType(_es) { Name = "15 years, Boys" };
   var gtboys16 = new GameType(_es) { Name = "16 years, Boys" };
   var gtgirls15 = new GameType(_es) { Name = "15 years, Girls" };

   // team types
   var ttb15=new TeamType(_es) { Name = "Boys 15 years" };
   var ttb16 = new TeamType(_es) { Name = "Boys 16 years" };
   var ttg15 = new TeamType(_es) { Name = "Girls 15 years" };

   // Valid team-game combinations
   gtgirls15.TeamTypes.Add(ttg15);

   gtboys15.TeamTypes.Add(ttb15);
   gtboys15.TeamTypes.Add(ttg15); // girls can play in boys 15 year
   gtboys16.TeamTypes.Add(ttb15); // 15 year boys can enter 16 year games
   gtboys16.TeamTypes.Add(ttb16);
   gtboys16.TeamTypes.Add(ttg15); // girls can play in boys 16 year



   new Team(_es) { Name = "Brynäs",Image=GetImage(imagebrynäs), TeamType=ttb15 };
   new Team(_es) { Name = "Brynäs", Image = GetImage(imagebrynäs), TeamType = ttb16 };
   new Team(_es) { Name = "Brynäs", Image = GetImage(imagebrynäs), TeamType = ttg15 };

   new Team(_es) { Name = "Luleå", Image = GetImage(imageluleå), TeamType = ttb15 };
   new Team(_es) { Name = "Luleå", Image = GetImage(imageluleå), TeamType = ttb16 };
   new Team(_es) { Name = "Luleå", Image = GetImage(imageluleå), TeamType = ttg15 };

   new Team(_es) { Name = "Djurgården", Image = GetImage(imagedjurgården), TeamType = ttb15  };
   new Team(_es) { Name = "Djurgården", Image = GetImage(imagedjurgården), TeamType = ttb16 };
   new Team(_es) { Name = "Djurgården", Image = GetImage(imagedjurgården), TeamType = ttg15 };

   return new Game(_es)
   {
       ScheduledDate = DateTime.Now
   };



Code Snippet <Window x:Class="WPFBinding.Window2"

   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:eco="clr-namespace:Eco.WPF;assembly=Eco.WPF"
   xmlns:ecoVM="clr-namespace:Eco.ViewModel.WPF;assembly=Eco.WPF"
   xmlns:Controls="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
   xmlns:local="clr-namespace:WPFBinding"
   xmlns:ecospace="clr-namespace:WPFBinding;assembly=WPFBinding.EcoSpace"
   Title="Window2" Height="300" Width="500" >
   <Window.Resources>
       <ecoVM:ViewModelContent x:Key="VM1" ViewModelName="GameSetup" EcoSpaceType="{x:Type ecospace:WPFBindingEcoSpace}" ></ecoVM:ViewModelContent>
       <local:ImageBlobConverter x:Key="ImageBlobConverter"/>
   </Window.Resources>
   <Grid>
       <Grid Name="vmrootStackPanel" DataContext="{StaticResource VM1}">
           <Grid.ColumnDefinitions>
               <ColumnDefinition></ColumnDefinition>
               <ColumnDefinition></ColumnDefinition>
               <ColumnDefinition Width="50"></ColumnDefinition>
           </Grid.ColumnDefinitions>
           <Grid.RowDefinitions>
               <RowDefinition></RowDefinition>
               <RowDefinition></RowDefinition>
               <RowDefinition></RowDefinition>
               <RowDefinition></RowDefinition>
               <RowDefinition></RowDefinition>
               <RowDefinition></RowDefinition>
               <RowDefinition></RowDefinition>
               <RowDefinition></RowDefinition>
           </Grid.RowDefinitions>

           <TextBlock Grid.Row="0" Grid.Column="0" Text="GAME : " HorizontalAlignment="Right" ></TextBlock>
           <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding  Path=Class[GameSetup]/Presentation,Mode=OneWay}"></TextBox>

           <TextBlock Grid.Row="1" Grid.Column="0" Text="Type of game : " HorizontalAlignment="Right" ></TextBlock>
           <ComboBox Grid.Row="1" Grid.Column="1"  DisplayMemberPath="Name"  ItemsSource="{Binding Path=Class[GameType_PickListPresentation]}" SelectedValuePath="self"  SelectedValue="{Binding Path=Class[GameSetup]/GameType}"  ></ComboBox>

           <TextBlock Grid.Row="2" Grid.Column="0" Text="Home team : " HorizontalAlignment="Right" ></TextBlock>
           <ComboBox Grid.Row="2" Grid.Column="1"  DisplayMemberPath="Name"  ItemsSource="{Binding Path=Class[Home_PickListPresentation]}" SelectedValuePath="self"  SelectedValue="{Binding Path=Class[GameSetup]/Home}"></ComboBox>
           <Image Grid.Row="2" Grid.Column="2"  Source="{Binding Path=Class[GameSetup]/Home_Image,Mode=OneWay,Converter={StaticResource ImageBlobConverter} }"></Image>


           <TextBlock Grid.Row="3" Grid.Column="0" Text="Visitor team : " HorizontalAlignment="Right" ></TextBlock>
           <ComboBox Grid.Row="3" Grid.Column="1"  DisplayMemberPath="Name"  ItemsSource="{Binding Path=Class[Visitor_PickListPresentation]}" SelectedValuePath="self"  SelectedValue="{Binding Path=Class[GameSetup]/Visitor}"></ComboBox>
           <Image Grid.Row="3" Grid.Column="2"  Source="{Binding Path=Class[GameSetup]/Visitor_Image,Mode=OneWay,Converter={StaticResource ImageBlobConverter} }"></Image>

           <TextBlock Grid.Row="4" Grid.Column="0" Text="Scheduled date : " HorizontalAlignment="Right" ></TextBlock>
           <Controls:DatePicker Grid.Row="4" Grid.Column="1"  ></Controls:DatePicker>

           <Button Grid.Row="5" Grid.Column="0" IsEnabled="{Binding Path=Class[GameSetup]/CanStartGame}" Click="ButtonStartGame_Click">
               <TextBlock Text="Start Game"></TextBlock>
           </Button>

           <Button  Grid.Row="5" Grid.Column="1"  IsEnabled="{Binding Path=Class[GameSetup]/CanEndGame}" >
               <TextBlock Text="End Game" ></TextBlock>
           </Button>

       </Grid>
        <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom">
           <Image Height="50" Name="imagebrynäs" Stretch="Fill" Width="50" Source="/WPFBinding;component/brynäs.jpg" />
           <Image Height="50" Name="imagedjurgården" Stretch="Fill" Width="50" Source="/WPFBinding;component/djurgården.jpg" />
           <Image Height="50" Name="imageluleå" Stretch="Fill" Width="50" Source="/WPFBinding;component/Luleå.jpg" />
       </StackPanel>
   </Grid>

</Window>

This page was edited 87 days ago on 02/13/2024. What links here