Add project files.

This commit is contained in:
2025-07-06 17:36:00 +02:00
parent 57be803688
commit 9e7a75b8c3
17 changed files with 426 additions and 0 deletions

View File

@ -0,0 +1,9 @@
namespace WpfLibrary;
public class DataAccess : IDataAccess
{
public string GetData()
{
return "This is the data from the Data Access class!";
}
}

View File

@ -0,0 +1,7 @@
namespace WpfLibrary
{
public interface IDataAccess
{
string GetData();
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

71
WinGreedWPF.sln Normal file
View File

@ -0,0 +1,71 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32630.192
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinGreedWPF", "WinGreedWPF\WinGreedWPF.csproj", "{09A80A37-40CF-472E-BCBC-B9FA801C06C6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinGreedLib", "WinGreedLibrary\WinGreedLib.csproj", "{65D28463-7B80-4D95-8170-AD17FB456F9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|ARM.ActiveCfg = Debug|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|ARM.Build.0 = Debug|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|ARM64.Build.0 = Debug|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|x64.ActiveCfg = Debug|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|x64.Build.0 = Debug|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|x86.ActiveCfg = Debug|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|x86.Build.0 = Debug|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|Any CPU.Build.0 = Release|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|ARM.ActiveCfg = Release|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|ARM.Build.0 = Release|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|ARM64.ActiveCfg = Release|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|ARM64.Build.0 = Release|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|x64.ActiveCfg = Release|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|x64.Build.0 = Release|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|x86.ActiveCfg = Release|Any CPU
{09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|x86.Build.0 = Release|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|ARM.ActiveCfg = Debug|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|ARM.Build.0 = Debug|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|ARM64.Build.0 = Debug|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|x64.ActiveCfg = Debug|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|x64.Build.0 = Debug|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|x86.ActiveCfg = Debug|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|x86.Build.0 = Debug|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|Any CPU.Build.0 = Release|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|ARM.ActiveCfg = Release|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|ARM.Build.0 = Release|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|ARM64.ActiveCfg = Release|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|ARM64.Build.0 = Release|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|x64.ActiveCfg = Release|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|x64.Build.0 = Release|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|x86.ActiveCfg = Release|Any CPU
{65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A6F6E52C-F6D0-4B6E-8F50-00FDF6DC3C40}
EndGlobalSection
EndGlobal

8
WinGreedWPF/App.xaml Normal file
View File

@ -0,0 +1,8 @@
<Application x:Class="WinGreedWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WinGreedWPF">
<Application.Resources>
</Application.Resources>
</Application>

42
WinGreedWPF/App.xaml.cs Normal file
View File

@ -0,0 +1,42 @@
using WinGreedWPF.StartupHelpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Windows;
using WpfLibrary;
namespace WinGreedWPF;
public partial class App : Application
{
public static IHost? AppHost { get; private set; }
public App()
{
AppHost = Host.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<MainWindow>();
services.AddFormFactory<ChildForm>();
services.AddFormFactory<ExtraChild>();
services.AddTransient<IDataAccess, DataAccess>();
})
.Build();
}
protected override async void OnStartup(StartupEventArgs e)
{
await AppHost!.StartAsync();
var startupForm = AppHost.Services.GetRequiredService<MainWindow>();
startupForm.Show();
base.OnStartup(e);
}
protected override async void OnExit(ExitEventArgs e)
{
await AppHost!.StopAsync();
base.OnExit(e);
}
}

View File

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@ -0,0 +1,16 @@
<Window x:Class="WinGreedWPF.ChildForm"
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:WinGreedWPF"
mc:Ignorable="d" FontSize="24"
Title="ChildForm" Height="200" Width="400"
WindowStartupLocation="CenterScreen">
<Grid>
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
<TextBlock>Child Form</TextBlock>
<TextBlock x:Name="dataAccessInfo"></TextBlock>
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,15 @@
using System.Windows;
using WpfLibrary;
namespace WinGreedWPF;
public partial class ChildForm : Window
{
private readonly IDataAccess _dataAccess;
public ChildForm(IDataAccess dataAccess)
{
InitializeComponent();
_dataAccess = dataAccess;
dataAccessInfo.Text = _dataAccess.GetData();
}
}

View File

@ -0,0 +1,14 @@
<Window x:Class="WinGreedWPF.ExtraChild"
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:WinGreedWPF"
mc:Ignorable="d"
Title="ExtraChild" Height="400" Width="300">
<Grid>
<StackPanel Orientation="Horizontal" Margin="10 5" VerticalAlignment="Center">
<TextBlock Text="ExtraChild" FontSize="30" />
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Shapes;
namespace WinGreedWPF
{
/// <summary>
/// Interaction logic for ExtraChild.xaml
/// </summary>
public partial class ExtraChild : Window
{
public ExtraChild()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,85 @@
<Window x:Class="WinGreedWPF.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:WinGreedWPF"
mc:Ignorable="d" FontSize="8"
Title="MainWindow" Height="500" Width="700"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.Children>
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Padding="20 10" FontSize="24" Text="Welcome to WinGreed!"/>
<Button Grid.Row="1" Grid.Column="0" FontSize="12" Padding="5 3" Margin="20 4 4 4" Click="NextPlayer">Spela en omgång</Button>
<ListView Grid.Row="2" Grid.Column="1" FontSize="12" Grid.ColumnSpan="4" Grid.RowSpan="4" Padding="5 3" Margin="20 4 4 4" >
<ListView.View >
<GridView >
<GridViewColumn Header="Namn" Width="150" >
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Background" Value="LightGray" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
<GridViewColumn Header="Vunnit" Width="40" >
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Background" Value="LightGray" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
<GridViewColumn Header="Poäng" Width="150">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Background" Value="LightGray" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<TextBlock Grid.Row="2" Grid.Column="6" Width="200" Grid.ColumnSpan="3" Padding="5 3" Background="LightGray" Margin="20 4 4 4" FontSize="12" FontWeight="Bold" Text="Logg"/>
<ListBox Grid.Row="3" Grid.Column="6" Width="200" FontSize="12" Grid.RowSpan="3" Padding="5 3" Margin="20 4 4 4" >
<ListBox.Items>
<ListBoxItem>
<TextBlock Text="xxxx xxx xxx "/>
</ListBoxItem>
<ListBoxItem>
<TextBlock Text="yy yyy yyy"/>
</ListBoxItem>
</ListBox.Items>
</ListBox>
<Button Grid.Row="1" Grid.Column="1" FontSize="12" Padding="5 3" Margin="20 4 4 4" Click="NewPlayer">Lägg in ny spelare</Button>
<TextBox x:Name="NameField" Grid.Row="1" Width="150" Grid.Column="2" Grid.ColumnSpan="2" FontSize="12" Padding="5 3" Margin="4 4 4 4" Visibility="Hidden" >N a m n</TextBox>
<Button Grid.Row="1" Grid.Column="4" FontSize="12" Padding="5 3" Margin="4 4 4 4" Click="NewConfirm">Ok</Button>
<StackPanel Grid.Row="4" Grid.Column="0" Orientation="Vertical" HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock x:Name="data"></TextBlock>
<Button x:Name="getData" Padding="20 10" Click="getData_Click" >Get Data</Button>
<Button x:Name="openChildForm" Padding="20 10" Click="openChildForm_Click" >Open Child Form</Button>
<Button x:Name="openExtraChildForm" Padding="20 10" Click="openExtraChildForm_Click" >Open Extra Child Form</Button>
</StackPanel>
</Grid.Children>
</Grid>
</Window>

View File

@ -0,0 +1,54 @@
using WinGreedWPF.StartupHelpers;
using System.Windows;
using WpfLibrary;
namespace WinGreedWPF;
public partial class MainWindow : Window
{
private readonly IDataAccess _dataAccess;
private readonly IAbstractFactory<ChildForm> _factory;
private readonly IAbstractFactory<ExtraChild> _extraCh;
public MainWindow(IDataAccess dataAccess,
IAbstractFactory<ChildForm> factory,
IAbstractFactory<ExtraChild> extraCh )
{
InitializeComponent();
_dataAccess = dataAccess;
_factory = factory;
_extraCh = extraCh;
}
private void getData_Click(object sender, RoutedEventArgs e)
{
data.Text=_dataAccess.GetData();
}
private void openChildForm_Click(object sender, RoutedEventArgs e)
{
_factory.Create().Show();
}
private void openExtraChildForm_Click(object sender, RoutedEventArgs e)
{
_extraCh.Create().Show();
}
private void NextPlayer(object sender, RoutedEventArgs e)
{
MessageBox.Show("Nytt spel");
}
private void NewPlayer(object sender, RoutedEventArgs e)
{
MessageBox.Show("Ny Spelare");
NameField.Visibility = Visibility.Visible;
}
private void NewConfirm(object sender, RoutedEventArgs e)
{
MessageBox.Show($"Ny Spelare {NameField.Text}");
NameField.Visibility = Visibility.Hidden;
}
}

View File

@ -0,0 +1,18 @@
using System;
namespace WinGreedWPF.StartupHelpers;
public class AbstractFactory<T> : IAbstractFactory<T>
{
private readonly Func<T> _factory;
public AbstractFactory(Func<T> factory)
{
_factory = factory;
}
public T Create()
{
return _factory();
}
}

View File

@ -0,0 +1,7 @@
namespace WinGreedWPF.StartupHelpers
{
public interface IAbstractFactory<T>
{
T Create();
}
}

View File

@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using System;
namespace WinGreedWPF.StartupHelpers;
public static class ServiceExtensions
{
public static void AddFormFactory<TForm>(this IServiceCollection services)
where TForm : class
{
services.AddTransient<TForm>();
services.AddSingleton<Func<TForm>>(x => () => x.GetService<TForm>()!);
services.AddSingleton<IAbstractFactory<TForm>, AbstractFactory<TForm>>();
}
}

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WinGreedLibrary\WinGreedLib.csproj" />
</ItemGroup>
</Project>