Browse Source

Merge pull request #82 from dotnet/xamarin-behaviors

Removed behaviors that aren't required and replaced with EventToComma…
pull/84/head
Javier Suárez Ruiz 8 years ago
committed by GitHub
parent
commit
4299c05039
8 changed files with 38 additions and 109 deletions
  1. +1
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml
  2. +0
    -52
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Behaviors/ItemTappedCommandListViewBehavior.cs
  3. +0
    -49
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Behaviors/WebViewNavigationBehavior.cs
  4. +0
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Converters/ItemTappedEventArgsConverter.cs
  5. +23
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Converters/WebNavigatingEventArgsConverter.cs
  6. +7
    -2
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/BasketView.xaml
  7. +5
    -3
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/LoginView.xaml
  8. +2
    -3
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj

+ 1
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml View File

@ -106,6 +106,7 @@
<converters:InverseBoolConverter x:Key="InverseBoolConverter" />
<converters:ItemsToHeightConverter x:Key="ItemsToHeightConverter" />
<converters:ToUpperConverter x:Key="ToUpperConverter" />
<converters:WebNavigatingEventArgsConverter x:Key="WebNavigatingEventArgsConverter" />
<!-- STYLES -->
<Style x:Key="EntryStyle"


+ 0
- 52
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Behaviors/ItemTappedCommandListViewBehavior.cs View File

@ -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);
}
}
}

+ 0
- 49
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Behaviors/WebViewNavigationBehavior.cs View File

@ -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);
}
}
}
}

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Converters/ItemTappedConverter.cs → src/Mobile/eShopOnContainers/eShopOnContainers.Core/Converters/ItemTappedEventArgsConverter.cs View File


+ 23
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Converters/WebNavigatingEventArgsConverter.cs View File

@ -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();
}
}
}

+ 7
- 2
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/BasketView.xaml View File

@ -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"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="eShopOnContainers.Core.Views.BasketView"
@ -76,12 +76,17 @@
<!-- ITEMS -->
<ListView
ItemsSource="{Binding BasketItems}"
behaviors:ItemTappedCommandListViewBehavior.ItemTappedCommand="{Binding AddCommand}"
HeightRequest="{Binding BasketItems.Count, Converter={StaticResource ItemsToHeightConverter}}"
HasUnevenRows="True"
SeparatorVisibility="None"
VerticalOptions="FillAndExpand"
CachingStrategy="RecycleElement">
<ListView.Behaviors>
<behaviors:EventToCommandBehavior
EventName="ItemTapped"
EventArgsConverter="{StaticResource ItemTappedEventArgsConverter}"
Command="{Binding AddCommand}" />
</ListView.Behaviors>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>


+ 5
- 3
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/LoginView.xaml View File

@ -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"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="eShopOnContainers.Core.Views.LoginView"
@ -313,8 +313,10 @@
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
AbsoluteLayout.LayoutFlags="All">
<WebView.Behaviors>
<behaviors:WebViewNavigationBehavior
NavigateCommand="{Binding NavigateCommand}"/>
<behaviors:EventToCommandBehavior
EventName="Navigating"
EventArgsConverter="{StaticResource WebNavigatingEventArgsConverter}"
Command="{Binding NavigateCommand}" />
</WebView.Behaviors>
</WebView>
</AbsoluteLayout>


+ 2
- 3
src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj View File

@ -44,8 +44,6 @@
</Compile>
<Compile Include="Behaviors\Base\BindableBehavior.cs" />
<Compile Include="Behaviors\EventToCommandBehavior.cs" />
<Compile Include="Behaviors\ItemTappedCommandListViewBehavior.cs" />
<Compile Include="Behaviors\WebViewNavigationBehavior.cs" />
<Compile Include="Controls\AddBasketButton.xaml.cs">
<DependentUpon>AddBasketButton.xaml</DependentUpon>
</Compile>
@ -58,7 +56,7 @@
<Compile Include="Converters\InverseBoolConverter.cs" />
<Compile Include="Converters\InverseCountToBoolConverter.cs" />
<Compile Include="Converters\ItemsToHeightConverter.cs" />
<Compile Include="Converters\ItemTappedConverter.cs" />
<Compile Include="Converters\ItemTappedEventArgsConverter.cs" />
<Compile Include="Converters\ToUpperConverter.cs" />
<Compile Include="Effects\LineColorEffect.cs" />
<Compile Include="Exceptions\ServiceAuthenticationException.cs" />
@ -166,6 +164,7 @@
<Compile Include="Views\Templates\ProductTemplate.xaml.cs">
<DependentUpon>ProductTemplate.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\WebNavigatingEventArgsConverter.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />


Loading…
Cancel
Save