Removed behaviors that aren't required and replaced with EventToCommandBehavior.
This commit is contained in:
parent
51006788b6
commit
3486e6be71
@ -106,6 +106,7 @@
|
|||||||
<converters:InverseBoolConverter x:Key="InverseBoolConverter" />
|
<converters:InverseBoolConverter x:Key="InverseBoolConverter" />
|
||||||
<converters:ItemsToHeightConverter x:Key="ItemsToHeightConverter" />
|
<converters:ItemsToHeightConverter x:Key="ItemsToHeightConverter" />
|
||||||
<converters:ToUpperConverter x:Key="ToUpperConverter" />
|
<converters:ToUpperConverter x:Key="ToUpperConverter" />
|
||||||
|
<converters:WebNavigatingEventArgsConverter x:Key="WebNavigatingEventArgsConverter" />
|
||||||
|
|
||||||
<!-- STYLES -->
|
<!-- STYLES -->
|
||||||
<Style x:Key="EntryStyle"
|
<Style x:Key="EntryStyle"
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
using System.Windows.Input;
|
|
||||||
using Xamarin.Forms;
|
|
||||||
|
|
||||||
namespace eShopOnContainers.Core.Behaviors
|
|
||||||
{
|
|
||||||
public sealed class ItemTappedCommandListViewBehavior
|
|
||||||
{
|
|
||||||
public static readonly BindableProperty ItemTappedCommandProperty =
|
|
||||||
BindableProperty.CreateAttached(
|
|
||||||
"ItemTappedCommand",
|
|
||||||
typeof(ICommand),
|
|
||||||
typeof(ItemTappedCommandListViewBehavior),
|
|
||||||
default(ICommand),
|
|
||||||
BindingMode.OneWay,
|
|
||||||
null,
|
|
||||||
PropertyChanged);
|
|
||||||
|
|
||||||
private static void PropertyChanged(BindableObject bindable, object oldValue, object newValue)
|
|
||||||
{
|
|
||||||
var listView = bindable as ListView;
|
|
||||||
if (listView != null)
|
|
||||||
{
|
|
||||||
listView.ItemTapped -= ListViewOnItemTapped;
|
|
||||||
listView.ItemTapped += ListViewOnItemTapped;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ListViewOnItemTapped(object sender, ItemTappedEventArgs e)
|
|
||||||
{
|
|
||||||
var list = sender as ListView;
|
|
||||||
if (list != null && list.IsEnabled && !list.IsRefreshing)
|
|
||||||
{
|
|
||||||
list.SelectedItem = null;
|
|
||||||
var command = GetItemTappedCommand(list);
|
|
||||||
if (command != null && command.CanExecute(e.Item))
|
|
||||||
{
|
|
||||||
command.Execute(e.Item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ICommand GetItemTappedCommand(BindableObject bindableObject)
|
|
||||||
{
|
|
||||||
return (ICommand)bindableObject.GetValue(ItemTappedCommandProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetItemTappedCommand(BindableObject bindableObject, object value)
|
|
||||||
{
|
|
||||||
bindableObject.SetValue(ItemTappedCommandProperty, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
using System.Windows.Input;
|
|
||||||
using Xamarin.Forms;
|
|
||||||
|
|
||||||
namespace eShopOnContainers.Core.Behaviors
|
|
||||||
{
|
|
||||||
public class WebViewNavigationBehavior : Behavior<WebView>
|
|
||||||
{
|
|
||||||
private VisualElement _element;
|
|
||||||
|
|
||||||
public static readonly BindableProperty NavigateCommandProperty =
|
|
||||||
BindableProperty.Create("NavigateCommand", typeof(ICommand),
|
|
||||||
typeof(WebViewNavigationBehavior), default(ICommand),
|
|
||||||
BindingMode.OneWay, null);
|
|
||||||
|
|
||||||
public ICommand NavigateCommand
|
|
||||||
{
|
|
||||||
get { return (ICommand)GetValue(NavigateCommandProperty); }
|
|
||||||
set { SetValue(NavigateCommandProperty, value); }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnAttachedTo(WebView bindable)
|
|
||||||
{
|
|
||||||
_element = bindable;
|
|
||||||
bindable.Navigating += OnWebViewNavigating;
|
|
||||||
bindable.BindingContextChanged += OnBindingContextChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnDetachingFrom(WebView bindable)
|
|
||||||
{
|
|
||||||
_element = null;
|
|
||||||
BindingContext = null;
|
|
||||||
bindable.Navigating -= OnWebViewNavigating;
|
|
||||||
bindable.BindingContextChanged -= OnBindingContextChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnBindingContextChanged(object sender, System.EventArgs e)
|
|
||||||
{
|
|
||||||
BindingContext = _element?.BindingContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnWebViewNavigating(object sender, WebNavigatingEventArgs e)
|
|
||||||
{
|
|
||||||
if (NavigateCommand != null && NavigateCommand.CanExecute(e.Url))
|
|
||||||
{
|
|
||||||
NavigateCommand.Execute(e.Url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace eShopOnContainers.Core.Converters
|
||||||
|
{
|
||||||
|
public class WebNavigatingEventArgsConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
var eventArgs = value as WebNavigatingEventArgs;
|
||||||
|
if (eventArgs == null)
|
||||||
|
throw new ArgumentException("Expected WebNavigatingEventArgs as value", "value");
|
||||||
|
|
||||||
|
return eventArgs.Url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="eShopOnContainers.Core.Views.BasketView"
|
x:Class="eShopOnContainers.Core.Views.BasketView"
|
||||||
@ -76,12 +76,17 @@
|
|||||||
<!-- ITEMS -->
|
<!-- ITEMS -->
|
||||||
<ListView
|
<ListView
|
||||||
ItemsSource="{Binding BasketItems}"
|
ItemsSource="{Binding BasketItems}"
|
||||||
behaviors:ItemTappedCommandListViewBehavior.ItemTappedCommand="{Binding AddCommand}"
|
|
||||||
HeightRequest="{Binding BasketItems.Count, Converter={StaticResource ItemsToHeightConverter}}"
|
HeightRequest="{Binding BasketItems.Count, Converter={StaticResource ItemsToHeightConverter}}"
|
||||||
HasUnevenRows="True"
|
HasUnevenRows="True"
|
||||||
SeparatorVisibility="None"
|
SeparatorVisibility="None"
|
||||||
VerticalOptions="FillAndExpand"
|
VerticalOptions="FillAndExpand"
|
||||||
CachingStrategy="RecycleElement">
|
CachingStrategy="RecycleElement">
|
||||||
|
<ListView.Behaviors>
|
||||||
|
<behaviors:EventToCommandBehavior
|
||||||
|
EventName="ItemTapped"
|
||||||
|
EventArgsConverter="{StaticResource ItemTappedEventArgsConverter}"
|
||||||
|
Command="{Binding AddCommand}" />
|
||||||
|
</ListView.Behaviors>
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ViewCell>
|
<ViewCell>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="eShopOnContainers.Core.Views.LoginView"
|
x:Class="eShopOnContainers.Core.Views.LoginView"
|
||||||
@ -313,8 +313,10 @@
|
|||||||
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
|
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
|
||||||
AbsoluteLayout.LayoutFlags="All">
|
AbsoluteLayout.LayoutFlags="All">
|
||||||
<WebView.Behaviors>
|
<WebView.Behaviors>
|
||||||
<behaviors:WebViewNavigationBehavior
|
<behaviors:EventToCommandBehavior
|
||||||
NavigateCommand="{Binding NavigateCommand}"/>
|
EventName="Navigating"
|
||||||
|
EventArgsConverter="{StaticResource WebNavigatingEventArgsConverter}"
|
||||||
|
Command="{Binding NavigateCommand}" />
|
||||||
</WebView.Behaviors>
|
</WebView.Behaviors>
|
||||||
</WebView>
|
</WebView>
|
||||||
</AbsoluteLayout>
|
</AbsoluteLayout>
|
||||||
|
@ -44,8 +44,6 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Behaviors\Base\BindableBehavior.cs" />
|
<Compile Include="Behaviors\Base\BindableBehavior.cs" />
|
||||||
<Compile Include="Behaviors\EventToCommandBehavior.cs" />
|
<Compile Include="Behaviors\EventToCommandBehavior.cs" />
|
||||||
<Compile Include="Behaviors\ItemTappedCommandListViewBehavior.cs" />
|
|
||||||
<Compile Include="Behaviors\WebViewNavigationBehavior.cs" />
|
|
||||||
<Compile Include="Controls\AddBasketButton.xaml.cs">
|
<Compile Include="Controls\AddBasketButton.xaml.cs">
|
||||||
<DependentUpon>AddBasketButton.xaml</DependentUpon>
|
<DependentUpon>AddBasketButton.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -58,7 +56,7 @@
|
|||||||
<Compile Include="Converters\InverseBoolConverter.cs" />
|
<Compile Include="Converters\InverseBoolConverter.cs" />
|
||||||
<Compile Include="Converters\InverseCountToBoolConverter.cs" />
|
<Compile Include="Converters\InverseCountToBoolConverter.cs" />
|
||||||
<Compile Include="Converters\ItemsToHeightConverter.cs" />
|
<Compile Include="Converters\ItemsToHeightConverter.cs" />
|
||||||
<Compile Include="Converters\ItemTappedConverter.cs" />
|
<Compile Include="Converters\ItemTappedEventArgsConverter.cs" />
|
||||||
<Compile Include="Converters\ToUpperConverter.cs" />
|
<Compile Include="Converters\ToUpperConverter.cs" />
|
||||||
<Compile Include="Effects\LineColorEffect.cs" />
|
<Compile Include="Effects\LineColorEffect.cs" />
|
||||||
<Compile Include="Exceptions\ServiceAuthenticationException.cs" />
|
<Compile Include="Exceptions\ServiceAuthenticationException.cs" />
|
||||||
@ -166,6 +164,7 @@
|
|||||||
<Compile Include="Views\Templates\ProductTemplate.xaml.cs">
|
<Compile Include="Views\Templates\ProductTemplate.xaml.cs">
|
||||||
<DependentUpon>ProductTemplate.xaml</DependentUpon>
|
<DependentUpon>ProductTemplate.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Converters\WebNavigatingEventArgsConverter.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user