This commit is contained in:
Sebastien Bovo 2019-01-24 15:27:30 +01:00
Родитель 2f534c039d
Коммит f61e2abc03
8 изменённых файлов: 137 добавлений и 40 удалений

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

@ -20,8 +20,9 @@
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"
Loaded="Window_Loaded"
Closed="Window_Closed"
mc:Ignorable="d"
Title="Add new expense" Height="800" Width="800"
Background="{StaticResource AddNewExpenseBackground}">
@ -60,12 +61,12 @@
<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" />
<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"/>
<local:CalendarViewWrapper Grid.Column="1" Grid.Row="6" x:Name="CalendarUwp" SelectedDatesChanged="CalendarUwp_SelectedDatesChanged" />
<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" />
<Button Content="Save" Grid.Row="8" Grid.Column="0" Click="OnSaveExpense" Margin="5, 12, 0, 0" HorizontalAlignment="Left" Width="180" />
</Grid>
</Window>

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

@ -17,6 +17,7 @@ using ContosoExpenses.Services;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
using System;
using System.Linq;
using System.Threading;
using System.Windows;
namespace ContosoExpenses
@ -60,33 +61,21 @@ namespace ContosoExpenses
}
}
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;
}
}
private void Window_Closed(object sender, EventArgs e)
{
CalendarUwp.Dispose();
}
private void CalendarUwp_SelectedDatesChanged(object sender, SelectedDatesChangedEventArgs e)
{
SelectedDate = e.SelectedDates.FirstOrDefault().Date;
txtDate.Text = SelectedDate.ToShortDateString();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
CalendarUwp.MinDate = DateTimeOffset.Now.AddYears(-1);
CalendarUwp.MaxDate = DateTimeOffset.Now;
}
}
}

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

@ -0,0 +1,82 @@
using Microsoft.Toolkit.Win32.UI.XamlHost;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContosoExpenses
{
public class CalendarViewWrapper : WindowsXamlHostBase
{
public event EventHandler<SelectedDatesChangedEventArgs> SelectedDatesChanged;
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
this.ChildInternal = UWPTypeFactory.CreateXamlContentByType("Windows.UI.Xaml.Controls.CalendarView");
SetContent();
Windows.UI.Xaml.Controls.CalendarView calendarView = this.ChildInternal as Windows.UI.Xaml.Controls.CalendarView;
calendarView.SelectedDatesChanged += CalendarView_SelectedDatesChanged;
}
private void CalendarView_SelectedDatesChanged(Windows.UI.Xaml.Controls.CalendarView sender, Windows.UI.Xaml.Controls.CalendarViewSelectedDatesChangedEventArgs args)
{
OnSelectedDatesChanged(new SelectedDatesChangedEventArgs(args.AddedDates));
}
public IList<DateTimeOffset> SelectedDates
{
get
{
if (this.ChildInternal != null)
{
global::Windows.UI.Xaml.Controls.CalendarView calendarView = this.ChildInternal as global::Windows.UI.Xaml.Controls.CalendarView;
return calendarView.SelectedDates;
}
return null;
}
}
private DateTimeOffset minDate;
public DateTimeOffset MinDate
{
get { return minDate; }
set
{
if (this.ChildInternal != null)
{
minDate = value;
Windows.UI.Xaml.Controls.CalendarView calendarView = this.ChildInternal as global::Windows.UI.Xaml.Controls.CalendarView;
calendarView.MinDate = value;
}
}
}
private DateTimeOffset maxDate;
public DateTimeOffset MaxDate
{
get { return maxDate; }
set
{
if (this.ChildInternal != null)
{
maxDate = value;
Windows.UI.Xaml.Controls.CalendarView calendarView = this.ChildInternal as global::Windows.UI.Xaml.Controls.CalendarView;
calendarView.MaxDate = value;
}
}
}
protected virtual void OnSelectedDatesChanged(SelectedDatesChangedEventArgs e)
{
SelectedDatesChanged?.Invoke(this, e);
}
}
}

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

@ -87,9 +87,11 @@
<Compile Include="AddNewExpense.xaml.cs">
<DependentUpon>AddNewExpense.xaml</DependentUpon>
</Compile>
<Compile Include="CalendarViewWrapper.cs" />
<Compile Include="ExpensesList.xaml.cs">
<DependentUpon>ExpensesList.xaml</DependentUpon>
</Compile>
<Compile Include="SelectedDatesChangedEventArgs.cs" />
<Compile Include="Services\DatabaseService.cs" />
<Page Include="AboutView.xaml">
<Generator>MSBuild:Compile</Generator>

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

@ -67,11 +67,11 @@
<TextBlock x:Name="txtLocation" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<!--<toolkit:MapControl Grid.Row="5" x:Name="ExpenseMap" />
<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" />-->
<toolkit:InkCanvas x:Name="Signature" Grid.Row="7" />
</Grid>

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

@ -31,9 +31,9 @@ namespace ContosoExpenses
public ExpenseDetail()
{
InitializeComponent();
//Signature.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen;
Signature.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen;
//MapService.ServiceToken = "IFFAI5SFOtHV9VBKF8Ea~3FS1XamCV2NM0IqlfoQo6A~AguqcUboJvnqWU1H9E-6MVThouJoCrM4wpv_1R_KX_oQLV_e59vyoK42470JvLsU";
MapService.ServiceToken = "IFFAI5SFOtHV9VBKF8Ea~3FS1XamCV2NM0IqlfoQo6A~AguqcUboJvnqWU1H9E-6MVThouJoCrM4wpv_1R_KX_oQLV_e59vyoK42470JvLsU";
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
@ -44,18 +44,18 @@ namespace ContosoExpenses
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);
//}
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();
Signature.Dispose();
ExpenseMap.Dispose();
}
}
}

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

@ -18,6 +18,7 @@
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"
@ -28,6 +29,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Menu IsMainMenu="True" Grid.Row="0">
@ -53,5 +55,8 @@
<DataGridTextColumn Header="E-mail" Binding="{Binding Path=Email}" />
</DataGrid.Columns>
</DataGrid>
<!--<xamlhost:WindowsXamlHost InitialTypeName="Windows.UI.Xaml.Controls.DataGrid" Grid.Row="2" x:Name="UwpGrid" />-->
</Grid>
</Window>

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

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContosoExpenses
{
public class SelectedDatesChangedEventArgs: EventArgs
{
public IReadOnlyList<DateTimeOffset> SelectedDates { get; set; }
public SelectedDatesChangedEventArgs(IReadOnlyList<DateTimeOffset> selectedDates)
{
this.SelectedDates = selectedDates;
}
}
}