Removed behaviors that aren't required and replaced with EventToComma…pull/84/head
@ -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(); | |||
} | |||
} | |||
} |