Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit d25e6da

Browse files
Merge branch 'develop'
2 parents 1b33703 + d972a68 commit d25e6da

8 files changed

Lines changed: 99 additions & 34 deletions

File tree

MaterialDesignControls.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata minClientVersion="2.8.1">
44
<id>Plugin.MaterialDesignControls</id>
5-
<version>1.4.1</version>
5+
<version>1.4.2</version>
66
<title>MaterialDesignControls Plugin for Xamarin Forms</title>
77
<authors>Horus</authors>
88
<owners>AgustinBonillaHorus</owners>

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ public class MyControl : ContentView, ITouchAndPressEffectConsumer
172172

173173
## Demo
174174
https://github.com/HorusSoftwareUY/MaterialDesignControlsPlugin/tree/master/example
175+
176+
## Developed by
177+
<a href="http://horus.com.uy" ><img src="https://horus.com.uy/img/logo_horus.png" width="128"></a>
175178

176179
## Contributions
177180
Contributions are welcome! If you find a bug want a feature added please report it.

example/ExampleMaterialDesignControls/Pages/MaterialPickerPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<material:MaterialPicker x:Name="pckColors" Type="Filled" LabelText="Color" AnimateError="True" />
1111
<material:MaterialPicker x:Name="pckSizes" SelectedItem="{Binding SelectedSizes}" Type="Outlined" LabelText="Size" />
1212
<material:MaterialPicker x:Name="pckModels" Type="Lined" LabelText="Model" LeadingIcon="color.png" />
13+
<Label x:Name="lblSelectedIndex" Text="SelectedIndex: -" />
1314
<material:MaterialButton Text="Save" Icon="save.png" Command="{Binding TapCommand}" />
1415
</StackLayout>
1516
</ScrollView>

example/ExampleMaterialDesignControls/Pages/MaterialPickerPage.xaml.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public MaterialPickerPage()
1515

1616
this.pckColors.ItemsSource = new List<string> { "Red", "Blue", "Green" };
1717
this.pckSizes.ItemsSource = new List<string> { "P", "M", "X", "XL" };
18+
1819
this.pckModels.ItemsSource = new List<string> { "Model A", "Model B", "Model C", "Model D" };
20+
this.pckModels.SelectedIndexChanged += PckModels_SelectedIndexChanged;
1921

2022
this.SelectedSizes = "M";
2123

@@ -24,6 +26,11 @@ public MaterialPickerPage()
2426
this.BindingContext = this;
2527
}
2628

29+
private void PckModels_SelectedIndexChanged(object sender, EventArgs e)
30+
{
31+
this.lblSelectedIndex.Text = $"SelectedIndex: {this.pckModels.SelectedIndex}";
32+
}
33+
2734
public ICommand TapCommand { get; set; }
2835

2936
public async void OnTap(object parameter)

src/MaterialDesignControls/Controls/MaterialChips.xaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:controls="clr-namespace:Plugin.MaterialDesignControls;assembly=Plugin.MaterialDesignControls" x:Class="Plugin.MaterialDesignControls.MaterialChips">
2+
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:controls="clr-namespace:Plugin.MaterialDesignControls;assembly=Plugin.MaterialDesignControls" xmlns:custom="clr-namespace:Plugin.MaterialDesignControls.Implementations;assembly=Plugin.MaterialDesignControls" x:Class="Plugin.MaterialDesignControls.MaterialChips">
33
<ContentView.Content>
44
<Frame x:Name="frmContainer" HasShadow="false" CornerRadius="16" Padding="12,0" MinimumHeightRequest="32" HeightRequest="32">
55
<StackLayout VerticalOptions="Center" Spacing="0" HorizontalOptions="Center" Orientation="Horizontal">
6-
<Grid x:Name="imgLeadingContainer" IsVisible="false" VerticalOptions="Center" HorizontalOptions="CenterAndExpand" WidthRequest="24" HeightRequest="26">
7-
<Image x:Name="imgLeading" HorizontalOptions="Start" VerticalOptions="CenterAndExpand" Aspect="AspectFit" WidthRequest="18" HeightRequest="18" />
8-
</Grid>
6+
<custom:CustomImageButton x:Name="imgLeadingIcon" IsVisible="false" HorizontalOptions="Start" Padding="0,0,4,0" ImageWidthRequest="18" ImageHeightRequest="18" />
97
<controls:MaterialLabel x:Name="lblText" HorizontalOptions="CenterAndExpand" LineBreakMode="NoWrap" VerticalOptions="Center" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" />
10-
<Grid x:Name="imgTrailingContainer" IsVisible="false" VerticalOptions="Center" HorizontalOptions="CenterAndExpand" WidthRequest="24" HeightRequest="26">
11-
<Image x:Name="imgTrailing" HorizontalOptions="End" VerticalOptions="CenterAndExpand" Aspect="AspectFit" WidthRequest="18" HeightRequest="18" />
12-
</Grid>
8+
<custom:CustomImageButton x:Name="imgTrailingIcon" IsVisible="false" HorizontalOptions="End" Padding="4,0,0,0" ImageWidthRequest="18" ImageHeightRequest="18" />
139
</StackLayout>
1410
</Frame>
1511
</ContentView.Content>

src/MaterialDesignControls/Controls/MaterialChips.xaml.cs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,12 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
298298
this.ApplyIsSelected();
299299
break;
300300
case nameof(this.TrailingIcon):
301-
this.imgTrailing.Source = this.TrailingIcon;
302-
this.imgTrailingContainer.IsVisible = true;
301+
this.imgTrailingIcon.Image.Source = this.TrailingIcon;
302+
this.imgTrailingIcon.IsVisible = true;
303303
break;
304304
case nameof(this.LeadingIcon):
305-
this.imgLeading.Source = this.LeadingIcon;
306-
this.imgLeadingContainer.IsVisible = true;
305+
this.imgTrailingIcon.Image.Source = this.LeadingIcon;
306+
this.imgTrailingIcon.IsVisible = true;
307307
break;
308308
case nameof(this.LeadingIconCommand):
309309
AddIconTapGesture(false);
@@ -322,32 +322,26 @@ private void AddIconTapGesture(bool isTrailingIcon)
322322
if (this.frmContainer.GestureRecognizers.Count > 0)
323323
this.frmContainer.GestureRecognizers.RemoveAt(0); //Remove main tap gesture
324324

325-
TapGestureRecognizer tapIconGestureRecognizer = new TapGestureRecognizer();
326-
tapIconGestureRecognizer.Tapped += (s, e) =>
325+
if (isTrailingIcon)
327326
{
328-
if (this.IsEnabled)
327+
this.imgTrailingIcon.Tapped = () =>
329328
{
330-
if (isTrailingIcon)
329+
if (this.IsEnabled && this.TrailingIconCommand != null)
331330
{
332-
if (this.TrailingIconCommand != null)
333-
{
334-
this.TrailingIconCommand.Execute(this.TrailingIconCommandParameter);
335-
}
331+
this.TrailingIconCommand.Execute(this.TrailingIconCommandParameter);
336332
}
337-
else
333+
};
334+
}
335+
else
336+
{
337+
this.imgLeadingIcon.Tapped = () =>
338+
{
339+
if (this.IsEnabled && this.LeadingIconCommand != null)
338340
{
339-
if (this.LeadingIconCommand != null)
340-
{
341-
this.LeadingIconCommand.Execute(this.LeadingIconCommandParameter);
342-
}
341+
this.LeadingIconCommand.Execute(this.LeadingIconCommandParameter);
343342
}
344-
}
345-
};
346-
347-
if (isTrailingIcon)
348-
imgTrailingContainer.GestureRecognizers.Add(tapIconGestureRecognizer);
349-
else
350-
imgLeadingContainer.GestureRecognizers.Add(tapIconGestureRecognizer);
343+
};
344+
}
351345
}
352346

353347
private void ApplyIsSelected()

src/MaterialDesignControls/Controls/MaterialPicker.xaml.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public MaterialPicker()
4141

4242
#endregion Attributes
4343

44+
#region Events
45+
46+
public event EventHandler SelectedIndexChanged;
47+
48+
#endregion Events
49+
4450
#region Properties
4551

4652
public static readonly BindableProperty TypeProperty =
@@ -233,6 +239,27 @@ public bool AnimateError
233239
set { SetValue(AnimateErrorProperty, value); }
234240
}
235241

242+
public int SelectedIndex
243+
{
244+
get
245+
{
246+
if (this.ItemsSource != null)
247+
{
248+
var index = 0;
249+
foreach (var item in this.ItemsSource)
250+
{
251+
if (index.Equals(this.pckOptions.SelectedIndex))
252+
{
253+
return index;
254+
}
255+
index++;
256+
}
257+
}
258+
259+
return -1;
260+
}
261+
}
262+
236263
#endregion Properties
237264

238265
#region Methods
@@ -432,6 +459,10 @@ private void PckOptions_SelectedIndexChanged(object sender, EventArgs e)
432459
if (index.Equals(this.pckOptions.SelectedIndex))
433460
{
434461
this.SelectedItem = item.ToString();
462+
if (this.SelectedIndexChanged != null)
463+
{
464+
this.SelectedIndexChanged.Invoke(this, e);
465+
}
435466
break;
436467
}
437468
index++;

src/MaterialDesignControls/Implementations/CustomImageButton.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Runtime.CompilerServices;
23
using Xamarin.Forms;
34

45
namespace Plugin.MaterialDesignControls.Implementations
@@ -33,6 +34,22 @@ public Action Tapped
3334

3435
public Image Image { get; set; }
3536

37+
public static readonly BindableProperty ImageHeightRequestProperty = BindableProperty.Create(nameof(ImageHeightRequest), typeof(double), typeof(CustomImageButton), defaultValue: 24.0);
38+
39+
public double ImageHeightRequest
40+
{
41+
get { return (double)GetValue(ImageHeightRequestProperty); }
42+
set { SetValue(ImageHeightRequestProperty, value); }
43+
}
44+
45+
public static readonly BindableProperty ImageWidthRequestProperty = BindableProperty.Create(nameof(ImageWidthRequest), typeof(double), typeof(CustomImageButton), defaultValue: 24.0);
46+
47+
public double ImageWidthRequest
48+
{
49+
get { return (double)GetValue(ImageWidthRequestProperty); }
50+
set { SetValue(ImageWidthRequestProperty, value); }
51+
}
52+
3653
public CustomImageButton()
3754
{
3855
this.Padding = 6;
@@ -41,11 +58,27 @@ public CustomImageButton()
4158
this.Image = new Image
4259
{
4360
VerticalOptions = LayoutOptions.Center,
44-
WidthRequest = 24,
45-
HeightRequest = 24,
61+
HorizontalOptions = LayoutOptions.Center,
62+
WidthRequest = this.ImageWidthRequest,
63+
HeightRequest = this.ImageHeightRequest,
4664
};
4765

4866
this.Content = this.Image;
4967
}
68+
69+
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
70+
{
71+
base.OnPropertyChanged(propertyName);
72+
73+
switch (propertyName)
74+
{
75+
case nameof(this.ImageWidthRequest):
76+
this.Image.WidthRequest = this.ImageWidthRequest;
77+
break;
78+
case nameof(this.ImageHeightRequest):
79+
this.Image.HeightRequest = this.ImageHeightRequest;
80+
break;
81+
}
82+
}
5083
}
5184
}

0 commit comments

Comments
 (0)