Updated the manual for Exercise 4

This commit is contained in:
Matteo Pagani 2019-01-14 22:19:12 +01:00
Родитель 9ea087436d
Коммит 10498ad046
42 изменённых файлов: 1727 добавлений и 7 удалений

Просмотреть файл

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0'">
<VisualStudioVersion>15.0</VisualStudioVersion>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x86">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x86">
<Configuration>Release</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|AnyCPU">
<Configuration>Debug</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|AnyCPU">
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup>
<WapProjPath Condition="'$(WapProjPath)'==''">$(MSBuildExtensionsPath)\Microsoft\DesktopBridge\</WapProjPath>
</PropertyGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
<PropertyGroup>
<ProjectGuid>2d8fd114-a304-45b1-bca2-16949103603e</ProjectGuid>
<TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<PackageCertificateKeyFile>ContosoExpenses.Package_TemporaryKey.pfx</PackageCertificateKeyFile>
<EntryPointProjectUniqueName>..\ContosoExpenses\ContosoExpenses.csproj</EntryPointProjectUniqueName>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<None Include="ContosoExpenses.Package_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include="Images\LockScreenLogo.scale-200.png" />
<Content Include="Images\Square150x150Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Images\StoreLogo.png" />
<Content Include="Images\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ContosoExpenses\ContosoExpenses.csproj" />
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
</Project>

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.9 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.6 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.2 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.1 KiB

Просмотреть файл

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">
<Identity
Name="5dde7e45-3be3-4273-a57d-93a49bbb14b2"
Publisher="CN=mpagani"
Version="1.0.0.0" />
<Properties>
<DisplayName>ContosoExpenses.Package</DisplayName>
<PublisherDisplayName>mpagani</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="ContosoExpenses.Package"
Description="ContosoExpenses.Package"
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile
Wide310x150Logo="Images\Wide310x150Logo.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>

Просмотреть файл

@ -0,0 +1,57 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28407.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContosoExpenses", "ContosoExpenses\ContosoExpenses.csproj", "{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}"
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "ContosoExpenses.Package", "ContosoExpenses.Package\ContosoExpenses.Package.wapproj", "{2D8FD114-A304-45B1-BCA2-16949103603E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x64.ActiveCfg = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x64.Build.0 = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x86.ActiveCfg = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x86.Build.0 = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|Any CPU.Build.0 = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x64.ActiveCfg = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x64.Build.0 = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x86.ActiveCfg = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x86.Build.0 = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x64.ActiveCfg = Debug|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x64.Build.0 = Debug|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x64.Deploy.0 = Debug|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x86.ActiveCfg = Debug|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x86.Build.0 = Debug|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x86.Deploy.0 = Debug|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|Any CPU.Build.0 = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|Any CPU.Deploy.0 = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x64.ActiveCfg = Release|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x64.Build.0 = Release|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x64.Deploy.0 = Release|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x86.ActiveCfg = Release|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x86.Build.0 = Release|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3BADFBD9-C57F-40A7-B058-D6B067196030}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,35 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.AboutView"
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"
mc:Ignorable="d" MinHeight="500" MinWidth="700" Height="500" Width="700">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock HorizontalAlignment="Center" FontSize="14" FontWeight="Bold" Margin="10">
Contoso Expenses is a 'modern application of yesterday tomorrow' from Contoso Corp.
</TextBlock>
<WebBrowser Grid.Row="1"
Source="https://contosocorpwebsite.azurewebsites.net/" />
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,27 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System.Linq;
using System.Linq.Expressions;
namespace ContosoExpenses
{
public partial class AboutView
{
public AboutView()
{
InitializeComponent();
}
}
}

Просмотреть файл

@ -0,0 +1,64 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.AddNewExpense"
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:ContosoExpenses"
mc:Ignorable="d"
Title="Add new expense" Height="450" Width="800"
Background="{StaticResource AddNewExpenseBackground}">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock FontSize="24" Text="Add new expense" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
<TextBlock Text="Type:" FontSize="16" FontWeight="Bold" Grid.Row="1" Grid.Column="0" />
<TextBox x:Name="txtType" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="1" Grid.Column="1" />
<TextBlock Text="Description:" FontSize="16" FontWeight="Bold" Grid.Row="2" Grid.Column="0" />
<TextBox x:Name="txtDescription" FontSize="16" Margin="5, 0, 0, 0" Width="400" Height="200" AcceptsReturn="True" Grid.Row="2" Grid.Column="1" />
<TextBlock Text="Amount:" FontSize="16" FontWeight="Bold" Grid.Row="3" Grid.Column="0" />
<TextBox x:Name="txtAmount" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="3" Grid.Column="1" />
<TextBlock Text="Location:" FontSize="16" FontWeight="Bold" Grid.Row="4" Grid.Column="0" />
<TextBox x:Name="txtLocation" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="4" Grid.Column="1" />
<TextBlock Text="City:" FontSize="16" FontWeight="Bold" Grid.Row="5" Grid.Column="0" />
<TextBox x:Name="txtCity" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="5" Grid.Column="1" />
<TextBlock Text="Date:" FontSize="16" FontWeight="Bold" Grid.Row="6" Grid.Column="0" />
<DatePicker x:Name="txtDate" Grid.Row="6" Grid.Column="1" Margin="5, 0, 0, 0" Width="400" />
<Button Content="Save" Grid.Row="7" Grid.Column="0" Click="OnSaveExpense" Margin="5, 12, 0, 0" HorizontalAlignment="Left" Width="180" />
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,59 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using ContosoExpenses.Models;
using ContosoExpenses.Services;
using System;
using System.Windows;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for AddNewExpense.xaml
/// </summary>
public partial class AddNewExpense : Window
{
public int EmployeeId { get; set; }
public AddNewExpense()
{
InitializeComponent();
}
private void OnSaveExpense(object sender, RoutedEventArgs e)
{
try
{
Expense expense = new Expense
{
Address = txtAmount.Text,
City = txtCity.Text,
Cost = Convert.ToDouble(txtAmount.Text),
Description = txtDescription.Text,
Type = txtType.Text,
Date = txtDate.SelectedDate.GetValueOrDefault(),
EmployeeId = EmployeeId
};
DatabaseService service = new DatabaseService();
service.SaveExpense(expense);
this.Close();
}
catch (Exception exc)
{
MessageBox.Show("Validation error. Please check your data.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

Просмотреть файл

@ -0,0 +1,55 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Application x:Class="ContosoExpenses.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ContosoExpenses"
StartupUri="MainWindow.xaml">
<Application.Resources>
<!--Background images-->
<ImageBrush x:Key="MainBackground"
ImageSource="Images\ExpensesBackground.jpg"
Stretch="UniformToFill" />
<ImageBrush x:Key="HorizontalBackground"
ImageSource="Images\HorizontalBackground.png"
Stretch="UniformToFill" />
<ImageBrush x:Key="ExpensesListBackground"
ImageSource="Images\ExpensesListBackground.png"
Stretch="Fill" />
<ImageBrush x:Key="AddNewExpenseBackground"
ImageSource="Images\AddNewExpense.png"
Stretch="UniformToFill" />
<!--Styles for DataGrid-->
<Style x:Key="DataGridHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="Foreground" Value="Black" />
</Style>
<Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
<Setter Property="Cursor" Value="Hand" />
</Style>
<SolidColorBrush x:Key="SemiTransparentBackground"
Color="#0073CF"
Opacity=".6" />
</Application.Resources>
</Application>

Просмотреть файл

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

Просмотреть файл

@ -0,0 +1,176 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ContosoExpenses</RootNamespace>
<AssemblyName>ContosoExpenses</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Images\contoso.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Bogus, Version=25.0.3.0, Culture=neutral, PublicKeyToken=fa1bb3f3f218129a, processorArchitecture=MSIL">
<HintPath>..\packages\Bogus.25.0.3\lib\net40\Bogus.dll</HintPath>
</Reference>
<Reference Include="LiteDB, Version=4.1.4.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
<HintPath>..\packages\LiteDB.4.1.4\lib\net40\LiteDB.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Toolkit.Wpf.UI.Controls, Version=5.0.0.0, Culture=neutral, PublicKeyToken=4aff67a105548ee2, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Toolkit.Wpf.UI.Controls.5.0.1\lib\net462\Microsoft.Toolkit.Wpf.UI.Controls.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Toolkit.Wpf.UI.XamlHost, Version=5.0.0.0, Culture=neutral, PublicKeyToken=4aff67a105548ee2, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Toolkit.Wpf.UI.XamlHost.5.0.1\lib\net462\Microsoft.Toolkit.Wpf.UI.XamlHost.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net" />
<Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="Windows">
<HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17763.0\Windows.winmd</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AddNewExpense.xaml.cs">
<DependentUpon>AddNewExpense.xaml</DependentUpon>
</Compile>
<Compile Include="ExpensesList.xaml.cs">
<DependentUpon>ExpensesList.xaml</DependentUpon>
</Compile>
<Compile Include="Services\DatabaseService.cs" />
<Page Include="AboutView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="AddNewExpense.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ExpenseDetail.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ExpensesList.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="AboutView.xaml.cs">
<DependentUpon>AboutView.xaml</DependentUpon>
</Compile>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="ExpenseDetail.xaml.cs">
<DependentUpon>ExpenseDetail.xaml</DependentUpon>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Models\Employee.cs" />
<Compile Include="Models\Expense.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\contoso.ico" />
</ItemGroup>
<ItemGroup>
<Content Include="Images\HorizontalBackground.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\AddNewExpense.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\ExpensesBackground.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\ExpensesListBackground.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,146 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.ExpenseDetail"
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:toolkit="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
Loaded="Window_Loaded"
Closed="Window_Closed"
xmlns:local="clr-namespace:ContosoExpenses"
mc:Ignorable="d"
Title="Expense Detail" Height="500" Width="800"
Background="{StaticResource HorizontalBackground}">
<Grid Margin="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!-- Expense detail -->
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock FontSize="24" Text="Expense" Grid.Row="0" />
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBlock Text="Type:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtType" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<TextBlock Text="Description:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtDescription" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<TextBlock Text="Amount:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtAmount" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="4">
<TextBlock Text="Location:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtLocation" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<toolkit:MapControl Grid.Row="5" x:Name="ExpenseMap" />
<TextBlock Text="Signature:" FontSize="16" FontWeight="Bold" Grid.Row="6" />
<toolkit:InkCanvas x:Name="Signature" Grid.Row="7" />
</Grid>
<!-- Chart -->
<DockPanel Grid.Column="1" VerticalAlignment="Bottom" Margin="20,0,0,0" MinHeight="420">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="Chart" Width="50" VerticalAlignment="Bottom">
<Rectangle StrokeThickness="1" RadiusX="2" RadiusY="2">
<Rectangle.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#4E87D4" Offset="0" />
<GradientStop Color="#73B2F5" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Stroke>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFFFFF" Offset="0" />
<GradientStop Color="#4E87D4" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
<Grid Grid.Column="1" Width="20" Height="400" VerticalAlignment="Bottom">
<Rectangle StrokeThickness="1" RadiusX="2" RadiusY="2">
<Rectangle.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF0000" Offset="0" />
<GradientStop Color="#4CFF00" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Stroke>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF0000" Offset="0" />
<GradientStop Color="#4CFF00" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Grid>
<TextBlock Grid.Column="2" Text="1000$ limit" Margin="0,20,0,0"></TextBlock>
</DockPanel>
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,61 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System;
using System.Linq;
using System.Windows;
using ContosoExpenses.Models;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
using Windows.Services.Maps;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for ExpenseDetail.xaml
/// </summary>
public partial class ExpenseDetail : Window
{
public Expense SelectedExpense { get; set; }
public ExpenseDetail()
{
InitializeComponent();
Signature.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen;
MapService.ServiceToken = "IFFAI5SFOtHV9VBKF8Ea~3FS1XamCV2NM0IqlfoQo6A~AguqcUboJvnqWU1H9E-6MVThouJoCrM4wpv_1R_KX_oQLV_e59vyoK42470JvLsU";
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
txtType.Text = SelectedExpense.Type;
txtDescription.Text = SelectedExpense.Description;
txtLocation.Text = SelectedExpense.Address;
txtAmount.Text = SelectedExpense.Cost.ToString();
Chart.Height = (SelectedExpense.Cost * 400) / 1000;
var result = await MapLocationFinder.FindLocationsAsync(SelectedExpense.Address, null);
var location = result.Locations.FirstOrDefault();
if (location != null)
{
await ExpenseMap.TrySetViewAsync(location.Point, 13);
}
}
private void Window_Closed(object sender, EventArgs e)
{
Signature.Dispose();
ExpenseMap.Dispose();
}
}
}

Просмотреть файл

@ -0,0 +1,80 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.ExpensesList"
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:ContosoExpenses"
mc:Ignorable="d"
Loaded="Window_Loaded"
Activated="Window_Activated"
Title="Expenses List" Height="450" Width="800"
Background="{StaticResource ExpensesListBackground}">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock FontSize="24" Text="Expenses List" Grid.Row="0" />
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBlock Text="Employee Id:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtEmployeeId" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<TextBlock Text="Full name:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtFullName" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<TextBlock Text="E-mail:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtEmail" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<DataGrid x:Name="ExpensesGrid"
Grid.Row="4"
SelectionChanged="OnSelectedExpense"
AutoGenerateColumns="False"
IsReadOnly="True"
Margin="0, 12, 0, 0"
SelectionMode="Single"
Background="{StaticResource SemiTransparentBackground}"
RowBackground="{StaticResource SemiTransparentBackground}"
ColumnHeaderStyle="{StaticResource DataGridHeaderStyle}"
RowStyle="{StaticResource DataGridRowStyle}"
Foreground="White"
FontSize="14">
<DataGrid.Columns>
<DataGridTextColumn Header="Date" Binding="{Binding Path=Date}" />
<DataGridTextColumn Header="Type" Binding="{Binding Path=Type}" />
<DataGridTextColumn Header="Description" Binding="{Binding Path=Description}" />
<DataGridTextColumn Header="Cost" Binding="{Binding Path=Cost}" />
<DataGridTextColumn Header="City" Binding="{Binding Path=City}" />
</DataGrid.Columns>
</DataGrid>
<Button Content="Add new expense" Click="OnAddNewExpense" Grid.Row="5" HorizontalAlignment="Left" Margin="0, 12, 0, 0" Width="180" />
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,89 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
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;
using ContosoExpenses.Models;
using ContosoExpenses.Services;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for ExpensesList.xaml
/// </summary>
public partial class ExpensesList : Window
{
public int EmployeeId { get; set; }
private Employee selectedEmployee;
public ExpensesList()
{
InitializeComponent();
}
private void OnSelectedExpense(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
var expense = e.AddedItems[0] as Expense;
if (expense != null && expense.ExpenseId != 0)
{
ExpenseDetail detail = new ExpenseDetail();
detail.SelectedExpense = expense;
detail.ShowDialog();
}
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DatabaseService databaseService = new DatabaseService();
selectedEmployee = databaseService.GetEmployee(EmployeeId);
txtEmployeeId.Text = selectedEmployee.EmployeeId.ToString();
txtFullName.Text = $"{selectedEmployee.FirstName} {selectedEmployee.LastName}";
txtEmail.Text = selectedEmployee.Email;
}
private void OnAddNewExpense(object sender, RoutedEventArgs e)
{
AddNewExpense newExpense = new AddNewExpense();
newExpense.EmployeeId = EmployeeId;
newExpense.ShowDialog();
}
public void LoadData()
{
DatabaseService databaseService = new DatabaseService();
ExpensesGrid.ItemsSource = databaseService.GetExpenses(EmployeeId);
}
private void Window_Activated(object sender, EventArgs e)
{
LoadData();
}
}
}

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.2 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 320 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 65 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 27 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 133 KiB

Просмотреть файл

@ -0,0 +1,57 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.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:ContosoExpenses"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="Contoso Expenses" Height="450" Width="800"
Background="{StaticResource MainBackground}">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Menu IsMainMenu="True" Grid.Row="0">
<MenuItem Header="_About" FontSize="12" Click="OnOpenAbout" />
</Menu>
<DataGrid x:Name="CustomersGrid"
Grid.Row="1"
SelectionChanged="OnSelectedEmployee"
AutoGenerateColumns="False"
SelectionMode="Single"
IsReadOnly="True"
Background="{StaticResource SemiTransparentBackground}"
RowBackground="{StaticResource SemiTransparentBackground}"
ColumnHeaderStyle="{StaticResource DataGridHeaderStyle}"
RowStyle="{StaticResource DataGridRowStyle}"
Foreground="White"
FontSize="14">
<DataGrid.Columns>
<DataGridTextColumn Header="Employee Id" Binding="{Binding Path=EmployeeId}" />
<DataGridTextColumn Header="Name" Binding="{Binding Path=FirstName}" />
<DataGridTextColumn Header="Surname" Binding="{Binding Path=LastName}" />
<DataGridTextColumn Header="E-mail" Binding="{Binding Path=Email}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,67 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using ContosoExpenses.Models;
using ContosoExpenses.Services;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LoadData();
}
private void LoadData()
{
List<Employee> customers = new List<Employee>();
DatabaseService db = new DatabaseService();
db.InitializeDatabase();
CustomersGrid.ItemsSource = db.GetEmployees();
}
private void OnSelectedEmployee(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
var employee = e.AddedItems[0] as Employee;
if (employee != null && employee.EmployeeId != 0)
{
ExpensesList detail = new ExpensesList();
detail.EmployeeId = employee.EmployeeId;
detail.Show();
}
}
}
private void OnOpenAbout(object sender, RoutedEventArgs e)
{
AboutView about = new AboutView();
about.ShowDialog();
}
}
}

Просмотреть файл

@ -0,0 +1,11 @@

namespace ContosoExpenses.Models
{
public class Employee
{
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,16 @@
using System;
namespace ContosoExpenses.Models
{
public class Expense
{
public int ExpenseId { get; set; }
public string Type { get; set; }
public string Description { get; set; }
public double Cost { get; set; }
public string Address { get; set; }
public string City { get; set; }
public DateTime Date { get; set; }
public int EmployeeId { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("XamlIslandDemo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("XamlIslandDemo")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[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)
)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ContosoExpenses.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ContosoExpenses.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

Просмотреть файл

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

Просмотреть файл

@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ContosoExpenses.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

Просмотреть файл

@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Bogus;
using LiteDB;
using ContosoExpenses.Models;
namespace ContosoExpenses.Services
{
public class DatabaseService
{
readonly int numberOfEmployees = 10;
readonly int numberOfExpenses = 5;
string filePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\ExpenseIt\\data.db";
string directoryPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\ExpenseIt\\";
public Employee GetEmployee(int employeeId)
{
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
return employees.FindById(employeeId);
}
}
public List<Employee> GetEmployees()
{
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
return employees.FindAll().ToList();
}
}
public List<Expense> GetExpenses(int employeedId)
{
using (var connection = new LiteDatabase(filePath))
{
var expenses = connection.GetCollection<Expense>();
return expenses.Find(x => x.EmployeeId == employeedId).ToList();
}
}
public void SaveExpense(Expense expense)
{
using (var connection = new LiteDatabase(filePath))
{
var expenses = connection.GetCollection<Expense>();
expenses.Insert(expense);
}
}
public void InitializeDatabase()
{
if (!File.Exists(filePath))
{
Directory.CreateDirectory(directoryPath);
}
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
var expenses = connection.GetCollection<Expense>();
int result = employees.Count();
if (result == 0)
{
GenerateFakeData(numberOfEmployees, numberOfExpenses);
}
}
}
private void GenerateFakeData(int numberOfEmployees, int numberOfExpenses)
{
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
var expenses = connection.GetCollection<Expense>();
for (int cont = 0; cont < numberOfEmployees; cont++)
{
var employee = new Faker<Employee>()
.RuleFor(x => x.FirstName, (f, u) => f.Name.FirstName())
.RuleFor(x => x.LastName, (f, u) => f.Name.LastName())
.RuleFor(x => x.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName, "contoso.com"))
.Generate();
int employeeId = employees.Insert(employee).AsInt32;
for (int contExpenses = 0; contExpenses < numberOfExpenses; contExpenses++)
{
var expense = new Faker<Expense>()
.RuleFor(x => x.Description, (f, u) => f.Commerce.ProductName())
.RuleFor(x => x.Type, (f, u) => f.Finance.TransactionType())
.RuleFor(x => x.Cost, (f, u) => (double)f.Finance.Amount())
.RuleFor(x => x.Address, (f, u) => f.Address.FullAddress())
.RuleFor(x => x.City, (f, u) => f.Address.City())
.RuleFor(x => x.Date, (f, u) => f.Date.Past())
.Generate();
expense.EmployeeId = employeeId;
expenses.Insert(expense);
}
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Bogus" version="25.0.3" targetFramework="net472" />
<package id="LiteDB" version="4.1.4" targetFramework="net472" />
<package id="Microsoft.Toolkit.Wpf.UI.Controls" version="5.0.1" targetFramework="net472" />
<package id="Microsoft.Toolkit.Wpf.UI.XamlHost" version="5.0.1" targetFramework="net472" />
</packages>

Просмотреть файл

@ -79,7 +79,8 @@ namespace ContosoExpenses
}
};
calendarView.SetDisplayDate(DateTime.Now);
calendarView.MinDate = DateTimeOffset.Now.AddYears(-1);
calendarView.MaxDate = DateTimeOffset.Now;
}
}

Двоичные данные
Manual/AddNewExpense.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 21 KiB

Двоичные данные
Manual/CalendarViewControl.jpg Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 28 KiB

Двоичные данные
Manual/CalendarViewControl.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 122 KiB

Просмотреть файл

@ -816,21 +816,219 @@ We are now ready to go further and use all the power of the full UWP ecosystem c
___
## Exercise - Integrate a custom UWP XAML component
TODO
The company has recently gone after a big hardware refresh and now all the managers are equipped with a Microsoft Surface or other touch equipped devices. Many managers would like to use the Contoso Expenses application on the go, without having to attach the keyboard, but the current version of the application isn't really touch friendly. The development team is looking to make the application easier to use with a touch device, without having to rewrite it from scratch with another technology.
Thanks to XAML Island, we can start replacing some WPF controls with the UWP counterpart, which are already optimized for multiple input experiences, like touch and pen.
### Task 1 - Reference the XAML Islands host conctrol
1. With the ExpenseIt solution opened in Visual Studio, right click on the ExpenseIt project and then **Manage NuGet Packages...**
The development team has decide to start modernizing the form to add a new expense, by making easier to choose the expense date with a touch device. The Universal Windows Platform offers a control called **CalendarView**, [which is perfect for our scenario](https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/calendar-view). It's the same control that it's integrated in Windows 10 when you click on the date and time in the taskbar:
![](CalendarViewControl.png)
However, it isn't included as a 1st party control in the Windows Community Toolkit, so we'll have to use the generic Windows Xaml Host control.
### Task 1 - Add the WindowsXamlHost control
1. You can use the output of Exercise 2 as a starting point. In case you haven't completed it, you can open the folder *"Lab/Exercise3/01-Start/ContosoExpenses"* in the location where you have unzipped the lab (it should be *"C:\XAMLIslandLab"*) and double click on the **ContosoExpenses.sln** file.
2. Regardless of your starting point, the required NuGet package should be already installed. We can verify this by right clicking on the **ContosoExpenses** project in Solution Explorer, choosing **Manage NuGet packages** and moving to the **Installed** tab.
![Manage NuGet Packages menu in Visual Studio](ManageNuGetPackages.png)
2. Search for the "Microsoft.Toolkit.Wpf.UI.XamlHost" package.
3. We should see a packaged called **Microsoft.Toolkit.Wpf.UI.XamlHost**.
![Microsoft.Toolkit.Wpf.UI.XamlHost NuGet Package](XamlHostNuGetPackages.png)
3. Click on the **Install** button.
4. The package is already installed because the one we have installed for exercises 1 and 2, **Microsoft.Toolkit.Wpf.UI.Control**, has a dependency on it. As such, when we have installed it in the previous exercises, NuGet automatically downloaded and installed also the **Microsoft.Toolkit.Wpf.UI.XamlHost** package.
5. Now we can start editing the code to add our control. Locate, in Solution Explorer, the file called **AddNewExpense.xaml** and double click on it. This is the form used to add a new expense to the list. Here is how it looks like in the current version of the application:
![](InstallNuGetPackage.png)
![](AddNewExpense.png)
As you can notice, the date picker control included in WPF is meant for traditional computers with mouse and keyboard. Choosing a date with a touch screen isn't really feasible, due to the small size of the control and the limited space between each day in the calendar.
6. We can see the current date picker implemented using the standard WPF control towards the end of the XAML file:
```xml
<DatePicker x:Name="txtDate" Grid.Row="6" Grid.Column="1" Margin="5, 0, 0, 0" Width="400" />
```
7. We're going to replace this control with the XAML Host one, which allows hosting any UWP control inside our WPF application. However, first, we need to add a new namespace to the page. Scroll to the top of the page, identify the **Window** tag and add the following attribute:
```xml
xmlns:xamlhost="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost"
```
This is how the full definition should look like:
```xml
<Window x:Class="ContosoExpenses.AddNewExpense"
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:xamlhost="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost"
xmlns:local="clr-namespace:ContosoExpenses"
mc:Ignorable="d"
Title="Add new expense" Height="450" Width="800"
Background="{StaticResource AddNewExpenseBackground}">
```
8. Now replace the **DatePicker** control you have previously identified in the XAML page with the following one:
```xml
<xamlhost:WindowsXamlHost InitialTypeName="Windows.UI.Xaml.Controls.CalendarView" Grid.Column="1" Grid.Row="6" Margin="5, 0, 0, 0" x:Name="CalendarUwp" />
```
We have added the **WindowsXamlHost** control, by using the **xamlhost** prefix we have just defined. The most important property to setup the control is **InitialTypeName**: you must specify the full name of the UWP control you want to host. In our case, we specify the full signature of the **CalendarView** control, which is **Windows.UI.Xaml.Controls.CalendarView**.
9. Let's test the work now. In order to compile our project, we need to make a small change. Locate the **AddNewExpense.xaml.cs** file in Solution Explorer and double click on it.
10. You will notice that there's a compilation error in the file. The **OnSaveExpenses()** method, in fact, contains the following code snippet:
```csharp
Expense expense = new Expense
{
Address = txtAmount.Text,
City = txtCity.Text,
Cost = Convert.ToDouble(txtAmount.Text),
Description = txtDescription.Text,
Type = txtType.Text,
Date = txtDate.SelectedDate.GetValueOrDefault(),
EmployeeId = EmployeeId
};
```
However, we have removed the WPF DatePicker control with name **txtDate** from the XAML page and, as such, the following line will return an error:
```csharp
Date = txtDate.SelectedDate.GetValueOrDefault()
```
For the moment, let's just comment it:
```csharp
//Date = txtDate.SelectedDate.GetValueOrDefault(),
```
Now press F5 to build and run the application. Once it starts, choose any employee from the list, then press the **Add new expense** button at the bottom of the list. You will notice how the WPF DatePicker control has been replaced with a full calendar view, which is more touch friendly. However, the work isn't completed yet. We need a way to handle the selected date, so that we can display it on the screen and we can store it in the code-behind, so that we can populate the new **Expense** object that gets saved in the database.
### Task 2 - Interact with the WindowsXamlHost control
Let's take a look [at the documentation](https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.CalendarView) of the **CalendarView** control. There are two things which are relevant for our scenario:
- The **SelectedDates** property, which contains the date selected by the user.
- The **SelectedDatesChanged** event, which is raised when the user selects a date
Let's go back to the **AddNewExpense.xaml** page and handle them.
> Can you guess which is the challenge here?
The **WindowsXamlHost** control is a generic host control for any kind of UWP control. As such, it doesn't expose any property called **SelectedDates** or any event called **SelectedDatesChanged**, since they are specific of the **CalendarView** control.
In order to implement our scenario, we need to move to the code behind and cast the **WindowsXamlHost** to the type we expect, in our case the **CalendarView** one. The best place to do is when the **ChildChanged** event is raised, which is triggered when the hosted control has been rendered.
1. Double click on the **AddNewExpense.xaml** file in Solution Explorer in Visual Studio
2. Identify the **WindowsXamlHost** control you have previously added and subscribe to the **ChildChanged** event:
```xml
<xamlhost:WindowsXamlHost InitialTypeName="Windows.UI.Xaml.Controls.CalendarView" Grid.Column="1" Grid.Row="6" Margin="5, 0, 0, 0" x:Name="CalendarUwp" ChildChanged="CalendarUwp_ChildChanged" />
```
3. Before moving on to the code behind, we need to add a **TextBlock** control to display the value selected by the user. First add a new **RowDefinition** with **Height** equal to **Auto** at the end of the **Grid.RowDefinitions** collection of the main **Grid**. This is how the final setup should look like:
```xml
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
```
4. Copy and paste the following code after the **WindowsXamlHost** control and before the **Button** one at the end of the XAML page:
```xml
<TextBlock Text="Selected date:" FontSize="16" FontWeight="Bold" Grid.Row="7" Grid.Column="0" />
<TextBlock x:Name="txtDate" FontSize="16" Grid.Row="7" Grid.Column="1" />
```
5. Locate the **Button** control at the end of the XAML page and change the **Grid.Row** property from **7** to **8**:
```xml
<Button Content="Save" Grid.Row="8" Grid.Column="0" Click="OnSaveExpense" Margin="5, 12, 0, 0" HorizontalAlignment="Left" Width="180" />
```
Since we have added a new row in the **Grid**, we need to shift the button of one row.
6. There's one last small change we need to make. If you remember when we have tested the application at the end of the previous task, the look and feel of the window wasn't really good. The reason is that the **CalendarView** control takes more space than the previous **DatePicker** and, as such, the current size of the window isn't enough to fit all the content. Let's incrase the height of the Window.
7. Locate the **Window** tag at the top of the XAML file.
8. Locate the **Height** property and change the value from **400** to **800**.
9. Also the **WindowsXamlHost** control must be properly disposed in order to be reused. As such, we need to subscribe to the **Closed** event also in this window, by adding the following attribute:
```xml
Closed="Window_Closed"
```
This is how the final definition of the **Window** element should look like:
```xml
<Window x:Class="ContosoExpenses.AddNewExpense"
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:xamlhost="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost"
xmlns:local="clr-namespace:ContosoExpenses"
mc:Ignorable="d"
Closed="Window_Closed"
Title="Add new expense" Height="800" Width="800"
Background="{StaticResource AddNewExpenseBackground}">
```
10. Now let's start to work on the code behind. Identify in Solution Explorer the **AddNewExpense.xaml.cs** file and double click on it.
11. First we need a property to hold a refernce to the selected date. Copy and paste the following definition inside the class:
```csharp
private DateTime SelectedDate;
```
11. Now copy and paste the following event handler inside the class definition:
```csharp
private void CalendarUwp_ChildChanged(object sender, EventArgs e)
{
WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender;
Windows.UI.Xaml.Controls.CalendarView calendarView =
(Windows.UI.Xaml.Controls.CalendarView)windowsXamlHost.Child;
if (calendarView != null)
{
calendarView.SelectedDatesChanged += (obj, args) =>
{
if (args.AddedDates.Count > 0)
{
SelectedDate = args.AddedDates.FirstOrDefault().DateTime;
txtDate.Text = SelectedDate.ToShortDateString();
}
};
calendarView.MinDate = DateTimeOffset.Now.AddYears(-1);
calendarView.MaxDate = DateTimeOffset.Now;
}
}
```
We are handling the **ChildChanged** event we have previously subscribed to. As first step, we retrieve a reference to the **WindowsXamlHost** control which triggered it. The control exposes a property called **Child**, which hosts the UWP control we have assigned with the **InitialTypeName** property. We retrieve this property and we cast it to the type of control we're hosting, which is **Windows.UI.Xaml.Controls.CalendarView**. Now we have access to the full UWP control, so we can:
- Subscribe to the **SelectedDatesChanged** event, which is triggered when the user selects a date from the calendar. Inside this handler, thanks to the event arguments, we have access to the **AddedDates** collection, which contains the selected dates. In our case we're using the **CalendarView** control in single selection mode, so the collection will contain only one element. We store it into the **SelectedDate** property we have previously created and we display it in the **txtDate** control.
- Customize the behavior of the control. Since, for compliance reasons, an employee can report only expenses occurred in the last year, it would be confusing to display dates older than 1 year or in the future. As such, we set the **MaxDate** property with the current date, while the **MinDate** one with the same date, but 1 year in the past. This means that if, for example, today is 14th February 2019, employees will be able to choose a date between 14th February 2018 and 14th February 2019.
___