Replaced custom BindablePicker with the updated Xamarin.Forms Picker control.
This commit is contained in:
parent
efb858f24e
commit
79c46984bb
@ -1,130 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using Xamarin.Forms;
|
|
||||||
|
|
||||||
namespace eShopOnContainers.Core.Controls
|
|
||||||
{
|
|
||||||
public class BindablePicker : Picker
|
|
||||||
{
|
|
||||||
public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource",
|
|
||||||
typeof(IEnumerable), typeof(BindablePicker), null, propertyChanged: OnItemsSourceChanged);
|
|
||||||
|
|
||||||
public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create("SelectedItem",
|
|
||||||
typeof(object), typeof(BindablePicker), null, BindingMode.TwoWay, propertyChanged: OnSelectedItemChanged);
|
|
||||||
|
|
||||||
public static readonly BindableProperty ItemSelectedCommandProperty = BindableProperty.Create("ItemSelectedCommand",
|
|
||||||
typeof(ICommand), typeof(BindablePicker), null);
|
|
||||||
|
|
||||||
public BindablePicker()
|
|
||||||
{
|
|
||||||
SelectedIndexChanged += (o, e) =>
|
|
||||||
{
|
|
||||||
if (SelectedIndex < 0 || ItemsSource == null || !ItemsSource.GetEnumerator().MoveNext())
|
|
||||||
{
|
|
||||||
SelectedItem = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var index = 0;
|
|
||||||
|
|
||||||
foreach (var item in ItemsSource)
|
|
||||||
{
|
|
||||||
if (index == SelectedIndex)
|
|
||||||
{
|
|
||||||
SelectedItem = item;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable ItemsSource
|
|
||||||
{
|
|
||||||
get { return (IEnumerable)GetValue(ItemsSourceProperty); }
|
|
||||||
set { SetValue(ItemsSourceProperty, value); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object SelectedItem
|
|
||||||
{
|
|
||||||
get { return GetValue(SelectedItemProperty); }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (SelectedItem != value)
|
|
||||||
{
|
|
||||||
SetValue(SelectedItemProperty, value);
|
|
||||||
InternalUpdateSelectedIndex();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICommand ItemSelectedCommand
|
|
||||||
{
|
|
||||||
get { return (ICommand)GetValue(ItemSelectedCommandProperty); }
|
|
||||||
set { SetValue(ItemSelectedCommandProperty, value); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public event EventHandler<SelectedItemChangedEventArgs> ItemSelected;
|
|
||||||
|
|
||||||
private void InternalUpdateSelectedIndex()
|
|
||||||
{
|
|
||||||
var selectedIndex = -1;
|
|
||||||
if (ItemsSource != null)
|
|
||||||
{
|
|
||||||
var index = 0;
|
|
||||||
|
|
||||||
foreach (var item in ItemsSource)
|
|
||||||
{
|
|
||||||
string strItem = item?.ToString();
|
|
||||||
|
|
||||||
if (item != null && SelectedItem != null
|
|
||||||
&& !string.IsNullOrEmpty(strItem)
|
|
||||||
&& item.ToString().Equals(SelectedItem.ToString()))
|
|
||||||
{
|
|
||||||
selectedIndex = index;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SelectedIndex = selectedIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)
|
|
||||||
{
|
|
||||||
var boundPicker = (BindablePicker)bindable;
|
|
||||||
|
|
||||||
if (Equals(newValue, null) && !Equals(oldValue, null))
|
|
||||||
return;
|
|
||||||
|
|
||||||
boundPicker.Items.Clear();
|
|
||||||
|
|
||||||
if (!Equals(newValue, null))
|
|
||||||
{
|
|
||||||
foreach (var item in (IEnumerable)newValue)
|
|
||||||
boundPicker.Items.Add(item.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
boundPicker.InternalUpdateSelectedIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue)
|
|
||||||
{
|
|
||||||
var boundPicker = (BindablePicker)bindable;
|
|
||||||
|
|
||||||
boundPicker.ItemSelected?.Invoke(boundPicker,
|
|
||||||
new SelectedItemChangedEventArgs(newValue));
|
|
||||||
|
|
||||||
if(boundPicker.ItemSelectedCommand != null)
|
|
||||||
{
|
|
||||||
boundPicker.ItemSelectedCommand.Execute(newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
boundPicker.InternalUpdateSelectedIndex();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<slideOverKit:SlideMenuView
|
<slideOverKit:SlideMenuView
|
||||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
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"
|
||||||
xmlns:slideOverKit="clr-namespace:SlideOverKit"
|
xmlns:slideOverKit="clr-namespace:SlideOverKit"
|
||||||
xmlns:controls="clr-namespace:eShopOnContainers.Core.Controls;assembly=eShopOnContainers.Core"
|
|
||||||
x:Class="eShopOnContainers.Core.Views.FiltersView"
|
x:Class="eShopOnContainers.Core.Views.FiltersView"
|
||||||
MenuOrientations="TopToBottom"
|
MenuOrientations="TopToBottom"
|
||||||
BackgroundColor="{StaticResource BackgroundColor}"
|
BackgroundColor="{StaticResource BackgroundColor}"
|
||||||
@ -13,7 +12,7 @@
|
|||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
|
|
||||||
<Style x:Key="FilterPickerStyle"
|
<Style x:Key="FilterPickerStyle"
|
||||||
TargetType="{x:Type controls:BindablePicker}">
|
TargetType="{x:Type Picker}">
|
||||||
<Setter Property="HeightRequest"
|
<Setter Property="HeightRequest"
|
||||||
Value="48" />
|
Value="48" />
|
||||||
<Setter Property="BackgroundColor"
|
<Setter Property="BackgroundColor"
|
||||||
@ -70,35 +69,35 @@
|
|||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<!-- BRAND -->
|
<!-- BRAND -->
|
||||||
<controls:BindablePicker
|
<Picker
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Title="BRAND"
|
Title="BRAND"
|
||||||
ItemsSource="{Binding Brands}"
|
ItemsSource="{Binding Brands}"
|
||||||
SelectedItem="{Binding Brand, Mode=TwoWay}"
|
SelectedItem="{Binding Brand, Mode=TwoWay}"
|
||||||
Style="{StaticResource FilterPickerStyle}">
|
Style="{StaticResource FilterPickerStyle}">
|
||||||
<controls:BindablePicker.HeightRequest>
|
<Picker.HeightRequest>
|
||||||
<OnPlatform
|
<OnPlatform
|
||||||
x:TypeArguments="x:Double"
|
x:TypeArguments="x:Double"
|
||||||
Android="48"
|
Android="48"
|
||||||
iOS="48"
|
iOS="48"
|
||||||
WinPhone="36"/>
|
WinPhone="36"/>
|
||||||
</controls:BindablePicker.HeightRequest>
|
</Picker.HeightRequest>
|
||||||
</controls:BindablePicker>
|
</Picker>
|
||||||
<!-- TYPE -->
|
<!-- TYPE -->
|
||||||
<controls:BindablePicker
|
<Picker
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Title="TYPE"
|
Title="TYPE"
|
||||||
ItemsSource="{Binding Types}"
|
ItemsSource="{Binding Types}"
|
||||||
SelectedItem="{Binding Type, Mode=TwoWay}"
|
SelectedItem="{Binding Type, Mode=TwoWay}"
|
||||||
Style="{StaticResource FilterPickerStyle}">
|
Style="{StaticResource FilterPickerStyle}">
|
||||||
<controls:BindablePicker.HeightRequest>
|
<Picker.HeightRequest>
|
||||||
<OnPlatform
|
<OnPlatform
|
||||||
x:TypeArguments="x:Double"
|
x:TypeArguments="x:Double"
|
||||||
Android="48"
|
Android="48"
|
||||||
iOS="48"
|
iOS="48"
|
||||||
WinPhone="36"/>
|
WinPhone="36"/>
|
||||||
</controls:BindablePicker.HeightRequest>
|
</Picker.HeightRequest>
|
||||||
</controls:BindablePicker>
|
</Picker>
|
||||||
<Button
|
<Button
|
||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
Text="Apply"
|
Text="Apply"
|
||||||
|
1
src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj
Executable file → Normal file
1
src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj
Executable file → Normal file
@ -47,7 +47,6 @@
|
|||||||
<Compile Include="Controls\AddBasketButton.xaml.cs">
|
<Compile Include="Controls\AddBasketButton.xaml.cs">
|
||||||
<DependentUpon>AddBasketButton.xaml</DependentUpon>
|
<DependentUpon>AddBasketButton.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Controls\BindablePicker.cs" />
|
|
||||||
<Compile Include="Controls\CustomTabbedPage.cs" />
|
<Compile Include="Controls\CustomTabbedPage.cs" />
|
||||||
<Compile Include="Controls\ToggleButton.cs" />
|
<Compile Include="Controls\ToggleButton.cs" />
|
||||||
<Compile Include="Converters\CountToBoolConverter.cs" />
|
<Compile Include="Converters\CountToBoolConverter.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user