Commits

Christian Specht committed b937e88 Draft

bind loaded command sets to listbox with buttons

Comments (0)

Files changed (8)

src/MissileSharp.Launcher/App.xaml

 <Application x:Class="MissileSharp.Launcher.App"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             StartupUri="MainWindow.xaml">
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     <Application.Resources>
          
     </Application.Resources>

src/MissileSharp.Launcher/App.xaml.cs

-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Data;
-using System.Linq;
-using System.Windows;
+using System.Windows;
+using MissileSharp.Launcher.ViewModels;
 
 namespace MissileSharp.Launcher
 {
     /// </summary>
     public partial class App : Application
     {
+        protected override void OnStartup(StartupEventArgs e)
+        {
+            base.OnStartup(e);
+
+            var window = new MainWindow();
+            var viewmodel = new MainWindowViewModel();
+            window.DataContext = viewmodel;
+            window.Show();
+        }
     }
 }

src/MissileSharp.Launcher/MainWindow.xaml

-<Window x:Class="MissileSharp.Launcher.MainWindow"
-        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        Title="MissileSharp Launcher" Height="350" Width="525">
-    <Grid>
-        
-    </Grid>
-</Window>

src/MissileSharp.Launcher/MainWindow.xaml.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-
-namespace MissileSharp.Launcher
-{
-    /// <summary>
-    /// Interaction logic for MainWindow.xaml
-    /// </summary>
-    public partial class MainWindow : Window
-    {
-        public MainWindow()
-        {
-            InitializeComponent();
-        }
-    }
-}

src/MissileSharp.Launcher/MissileSharp.Launcher.csproj

       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
-    <Page Include="MainWindow.xaml">
+    <Page Include="Views\MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
       <DependentUpon>App.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="MainWindow.xaml.cs">
+    <Compile Include="ViewModels\MainWindowViewModel.cs" />
+    <Compile Include="Views\MainWindow.xaml.cs">
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
       <Name>MissileSharp</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <Content Include="..\MissileSharp.Demo\settings.txt">
+      <Link>settings.txt</Link>
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

src/MissileSharp.Launcher/ViewModels/MainWindowViewModel.cs

+using System.Collections.ObjectModel;
+using System.ComponentModel;
+
+namespace MissileSharp.Launcher.ViewModels
+{
+    public class MainWindowViewModel : INotifyPropertyChanged
+    {
+        private CommandCenter model;
+
+        public ObservableCollection<string> CommandSets { get; set; }
+
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        public MainWindowViewModel()
+        {
+            model = new CommandCenter(new ThunderMissileLauncher());
+            model.LoadCommandSets("settings.txt");
+
+            this.CommandSets = new ObservableCollection<string>(model.GetLoadedCommandSetNames());
+        }
+    }
+}

src/MissileSharp.Launcher/Views/MainWindow.xaml

+<Window x:Class="MissileSharp.Launcher.MainWindow"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        Title="MissileSharp Launcher" Height="350" Width="525">
+    <Grid>
+        <ListBox ItemsSource="{Binding CommandSets}">
+            <ListBox.ItemTemplate>
+                <DataTemplate>
+                    <Button Content="{Binding}" />
+                </DataTemplate>
+            </ListBox.ItemTemplate>
+        </ListBox>
+    </Grid>
+</Window>

src/MissileSharp.Launcher/Views/MainWindow.xaml.cs

+using System.Windows;
+
+namespace MissileSharp.Launcher
+{
+    /// <summary>
+    /// Interaction logic for MainWindow.xaml
+    /// </summary>
+    public partial class MainWindow : Window
+    {
+        public MainWindow()
+        {
+            InitializeComponent();
+        }
+    }
+}