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

Commit 6fdf4ae

Browse files
Apply improvements on button, slider and entry
1 parent a23246d commit 6fdf4ae

8 files changed

Lines changed: 196 additions & 15 deletions

File tree

example/ExampleMaterialDesignControls/Pages/MaterialButtonPage.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
<StackLayout Padding="16" Spacing="16">
1414
<material:MaterialButton Text="Save" ToUpper="True" Icon="save.png" Command="{Binding TapCommand}" CommandParameter="Saved" IsBusy="{Binding IsBusy}" CornerRadius="14" />
1515

16-
<material:MaterialOutlineButton Text="Cancel" Command="{Binding TapCommand}" CommandParameter="Canceled" CornerRadius="14" IconSize="34" ActivityIndicatorSize="34">
16+
<material:MaterialOutlineButton Text="Cancel action" Command="{Binding TapCommand}" CommandParameter="Canceled" CornerRadius="14"
17+
IconSize="34" ActivityIndicatorSize="34"
18+
Padding="16,0" ContentIsExpanded="True" Spacing="0" WidthRequest="295" HorizontalOptions="Center">
1719
<material:MaterialButton.CustomIcon>
1820
<ffimageloadingsvg:SvgCachedImage Source="resource://ExampleMaterialDesignControls.Resources.Svg.ic_help_b.svg"/>
1921
</material:MaterialButton.CustomIcon>

example/ExampleMaterialDesignControls/Pages/MaterialEntryPage.xaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
</material:MaterialEntry.CustomHidePasswordIcon>
2323
</material:MaterialEntry>
2424

25-
<material:MaterialEntry Type="Outlined" LabelText="Confirm password" Placeholder="Enter" IsPassword="true" TabIndex="4" ReturnType="Next" CornerRadius="20" />
25+
<material:MaterialEntry Type="Outlined" LabelText="Confirm password" Placeholder="Enter" IsPassword="true" TabIndex="4" CornerRadius="20"
26+
ReturnType="Done" ReturnCommand="{Binding TapCommand}" />
2627
<material:MaterialEntry Type="Filled" LabelText="Phone" Placeholder="Enter your phone" Keyboard="Telephone" TabIndex="5" ReturnType="Next"
2728
FocusedBorderColor="LightGreen" FocusedTextColor="Green" FocusedLabelTextColor="Green" HorizontalTextAlignment="Center" />
2829
<material:MaterialEntry Type="Filled" LabelText="Phone" Placeholder="Enter your phone" Keyboard="Telephone" TabIndex="5" ReturnType="Next" IsEnabled="False" />
2930

30-
<material:MaterialEntry Type="Filled" LabelText="Phone (SVG trailing icon)" Placeholder="Enter your phone" Keyboard="Telephone" TabIndex="5" ReturnType="Next"
31-
TrailingIconCommand="{Binding HelpCommand}" TrailingIconCommandParameter="Enter your phone">
31+
<material:MaterialEntry Type="Filled" LabelText="Phone (SVG trailing icon)" Placeholder="Enter your phone" Keyboard="Telephone" TabIndex="5"
32+
TrailingIconCommand="{Binding HelpCommand}" TrailingIconCommandParameter="Enter your phone"
33+
LabelMargin="0,0,0,2" AssistiveMargin="0,2,0,0" AssistiveText="Testing">
3234
<material:MaterialEntry.CustomTrailingIcon>
3335
<ffimageloadingsvg:SvgCachedImage Source="resource://ExampleMaterialDesignControls.Resources.Svg.ic_help_b.svg"/>
3436
</material:MaterialEntry.CustomTrailingIcon>

example/ExampleMaterialDesignControls/Pages/MaterialSliderPage.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
ThumbColor="Blue"
1616
LabelText="Slider"
1717
ActiveTrackColor="Blue"
18-
InactiveTrackColor="LightBlue"/>
18+
InactiveTrackColor="LightBlue"
19+
LabelValueIsVisible="True"
20+
LabelValueFormat="0.00 km"
21+
LabelValueSize="12"
22+
LabelValueColor="Blue" />
1923

2024
<material:MaterialSlider
2125
x:Name="slider0"

src/MaterialDesignControls/Controls/BaseMaterialFieldControl.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ public double LabelSize
183183
set { SetValue(LabelSizeProperty, value); }
184184
}
185185

186+
public static readonly BindableProperty LabelMarginProperty =
187+
BindableProperty.Create(nameof(LabelMargin), typeof(Thickness), typeof(BaseMaterialFieldControl), defaultValue: new Thickness(14, 0, 14, 2));
188+
189+
public Thickness LabelMargin
190+
{
191+
get { return (Thickness)GetValue(LabelMarginProperty); }
192+
set { SetValue(LabelMarginProperty, value); }
193+
}
194+
186195
#endregion LabelText
187196

188197
#region AssistiveText
@@ -214,6 +223,15 @@ public double AssistiveSize
214223
set { SetValue(AssistiveSizeProperty, value); }
215224
}
216225

226+
public static readonly BindableProperty AssistiveMarginProperty =
227+
BindableProperty.Create(nameof(AssistiveMargin), typeof(Thickness), typeof(BaseMaterialFieldControl), defaultValue: new Thickness(14, 2, 14, 0));
228+
229+
public Thickness AssistiveMargin
230+
{
231+
get { return (Thickness)GetValue(AssistiveMarginProperty); }
232+
set { SetValue(AssistiveMarginProperty, value); }
233+
}
234+
217235
#endregion AssistiveText
218236

219237
#region Border
@@ -460,6 +478,9 @@ protected void UpdateLayout(string propertyName, Label lblLabel, Label lblAssist
460478
case nameof(LabelSize):
461479
lblLabel.FontSize = LabelSize;
462480
break;
481+
case nameof(LabelMargin):
482+
lblLabel.Margin = LabelMargin;
483+
break;
463484
case nameof(Padding):
464485
SetPadding();
465486
break;
@@ -502,6 +523,9 @@ protected void UpdateLayout(string propertyName, Label lblLabel, Label lblAssist
502523
case nameof(AssistiveSize):
503524
lblAssistive.FontSize = AssistiveSize;
504525
break;
526+
case nameof(AssistiveMargin):
527+
lblAssistive.Margin = AssistiveMargin;
528+
break;
505529

506530
case nameof(LeadingIcon):
507531
if (!string.IsNullOrEmpty(LeadingIcon))

src/MaterialDesignControls/Controls/MaterialButton.cs

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public string Icon
223223
}
224224

225225
public static readonly BindableProperty IconSizeProperty =
226-
BindableProperty.Create(nameof(IconSize), typeof(double), typeof(BaseMaterialFieldControl), defaultValue: 24.0);
226+
BindableProperty.Create(nameof(IconSize), typeof(double), typeof(MaterialButton), defaultValue: 24.0);
227227

228228
public double IconSize
229229
{
@@ -250,14 +250,41 @@ public View CustomActivityIndicator
250250
}
251251

252252
public static readonly BindableProperty ActivityIndicatorSizeProperty =
253-
BindableProperty.Create(nameof(ActivityIndicatorSize), typeof(double), typeof(BaseMaterialFieldControl), defaultValue: 24.0);
253+
BindableProperty.Create(nameof(ActivityIndicatorSize), typeof(double), typeof(MaterialButton), defaultValue: 24.0);
254254

255255
public double ActivityIndicatorSize
256256
{
257257
get { return (double)GetValue(ActivityIndicatorSizeProperty); }
258258
set { SetValue(ActivityIndicatorSizeProperty, value); }
259259
}
260260

261+
public static readonly new BindableProperty PaddingProperty =
262+
BindableProperty.Create(nameof(Padding), typeof(Thickness), typeof(MaterialButton), defaultValue: new Thickness(12, 0));
263+
264+
public new Thickness Padding
265+
{
266+
get { return (Thickness)GetValue(PaddingProperty); }
267+
set { SetValue(PaddingProperty, value); }
268+
}
269+
270+
public static readonly BindableProperty SpacingProperty =
271+
BindableProperty.Create(nameof(Spacing), typeof(int), typeof(MaterialButton), defaultValue: 12);
272+
273+
public int Spacing
274+
{
275+
get { return (int)GetValue(SpacingProperty); }
276+
set { SetValue(SpacingProperty, value); }
277+
}
278+
279+
public static readonly BindableProperty ContentIsExpandedProperty =
280+
BindableProperty.Create(nameof(ContentIsExpanded), typeof(bool), typeof(MaterialButton), defaultValue: false);
281+
282+
public bool ContentIsExpanded
283+
{
284+
get { return (bool)GetValue(ContentIsExpandedProperty); }
285+
set { SetValue(ContentIsExpandedProperty, value); }
286+
}
287+
261288
public event EventHandler Clicked;
262289

263290
#endregion Properties
@@ -274,15 +301,15 @@ private void Initialize()
274301
CornerRadius = 4,
275302
MinimumHeightRequest = 40,
276303
HeightRequest = 40,
277-
Padding = new Thickness(12, 0)
304+
Padding = this.Padding
278305
};
279306
Content = frmLayout;
280307

281308
stcLayout = new StackLayout
282309
{
283310
Orientation = StackOrientation.Horizontal,
284-
Spacing = 12,
285-
HorizontalOptions = LayoutOptions.Center,
311+
Spacing = this.Spacing,
312+
HorizontalOptions = this.ContentIsExpanded ? LayoutOptions.FillAndExpand : LayoutOptions.Center,
286313
};
287314
frmLayout.Content = stcLayout;
288315

@@ -298,7 +325,8 @@ private void Initialize()
298325
lblText = new MaterialLabel
299326
{
300327
LineBreakMode = LineBreakMode.NoWrap,
301-
VerticalOptions = LayoutOptions.Center
328+
VerticalOptions = LayoutOptions.Center,
329+
HorizontalOptions = this.ContentIsExpanded ? LayoutOptions.CenterAndExpand : LayoutOptions.Center
302330
};
303331
stcLayout.Children.Add(lblText);
304332

@@ -462,6 +490,17 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
462490
this.frmLayout.BorderColor = this.IsEnabled ? this.BorderColor : this.DisabledBorderColor;
463491
}
464492
break;
493+
494+
case nameof(this.Padding):
495+
frmLayout.Padding = this.Padding;
496+
break;
497+
case nameof(this.Spacing):
498+
stcLayout.Spacing = this.Spacing;
499+
break;
500+
case nameof(ContentIsExpanded):
501+
stcLayout.HorizontalOptions = this.ContentIsExpanded ? LayoutOptions.FillAndExpand : LayoutOptions.Center;
502+
lblText.HorizontalOptions = this.ContentIsExpanded ? LayoutOptions.CenterAndExpand : LayoutOptions.Center;
503+
break;
465504
}
466505
}
467506

src/MaterialDesignControls/Controls/MaterialEntry.xaml.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.CompilerServices;
3+
using System.Windows.Input;
34
using Plugin.MaterialDesignControls.Implementations;
45
using Plugin.MaterialDesignControls.Utils;
56
using Xamarin.Forms;
@@ -148,6 +149,24 @@ public ReturnType ReturnType
148149
set { SetValue(ReturnTypeProperty, value); }
149150
}
150151

152+
public static readonly BindableProperty ReturnCommandProperty =
153+
BindableProperty.Create(nameof(ReturnCommand), typeof(ICommand), typeof(MaterialEntry), defaultValue: null);
154+
155+
public ICommand ReturnCommand
156+
{
157+
get { return (ICommand)GetValue(ReturnCommandProperty); }
158+
set { SetValue(ReturnCommandProperty, value); }
159+
}
160+
161+
public static readonly BindableProperty ReturnCommandParameterProperty =
162+
BindableProperty.Create(nameof(ReturnCommandParameter), typeof(object), typeof(MaterialEntry), defaultValue: null);
163+
164+
public object ReturnCommandParameter
165+
{
166+
get { return (object)GetValue(ReturnCommandParameterProperty); }
167+
set { SetValue(ReturnCommandParameterProperty, value); }
168+
}
169+
151170
public static readonly BindableProperty TextProperty =
152171
BindableProperty.Create(nameof(Text), typeof(string), typeof(MaterialEntry), defaultValue: null, propertyChanged: OnTextChanged, defaultBindingMode: BindingMode.TwoWay);
153172

@@ -393,7 +412,7 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
393412
case nameof(this.ReturnType):
394413
this.txtEntry.ReturnType = this.ReturnType;
395414

396-
if (this.ReturnType.Equals(Xamarin.Forms.ReturnType.Next))
415+
if (this.ReturnType.Equals(Xamarin.Forms.ReturnType.Next) && this.ReturnCommand == null)
397416
{
398417
this.txtEntry.ReturnCommand = new Command(() =>
399418
{
@@ -402,6 +421,12 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
402421
});
403422
}
404423
break;
424+
case nameof(this.ReturnCommand):
425+
this.txtEntry.ReturnCommand = this.ReturnCommand;
426+
break;
427+
case nameof(this.ReturnCommandParameter):
428+
this.txtEntry.ReturnCommandParameter = this.ReturnCommandParameter;
429+
break;
405430
case nameof(this.IsCode):
406431
this.txtEntry.IsCode = this.IsCode;
407432
break;

src/MaterialDesignControls/Controls/MaterialSlider.xaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@
66
x:Class="Plugin.MaterialDesignControls.MaterialSlider">
77
<ContentView.Content>
88
<StackLayout Spacing="2">
9-
<controls:MaterialLabel x:Name="lblLabel" IsVisible="false" LineBreakMode="NoWrap" Margin="0,0,14,2" HorizontalTextAlignment="Start" />
9+
<StackLayout x:Name="stcHeader" Margin="0,0,14,2" Orientation="Horizontal">
10+
<controls:MaterialLabel
11+
x:Name="lblLabel"
12+
IsVisible="false"
13+
LineBreakMode="NoWrap"
14+
HorizontalOptions="FillAndExpand"
15+
HorizontalTextAlignment="Start"
16+
VerticalTextAlignment="Center" />
17+
<controls:MaterialLabel
18+
x:Name="lblValue"
19+
IsVisible="false"
20+
LineBreakMode="NoWrap"
21+
HorizontalTextAlignment="End"
22+
VerticalTextAlignment="Center" />
23+
</StackLayout>
1024
<Grid Padding="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" HeightRequest="50" Margin="0">
1125
<custom:CustomImage x:Name="bckgImage" IsVisible="false" Padding="10,0" />
1226
<StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand" >

src/MaterialDesignControls/Controls/MaterialSlider.xaml.cs

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,55 @@ public double LabelSize
7575

7676
#endregion LabelText
7777

78+
#region LabelValue
79+
80+
public static readonly BindableProperty LabelValueFormatProperty =
81+
BindableProperty.Create(nameof(LabelValueFormat), typeof(string), typeof(MaterialSlider), defaultValue: null);
82+
83+
public string LabelValueFormat
84+
{
85+
get { return (string)GetValue(LabelValueFormatProperty); }
86+
set { SetValue(LabelValueFormatProperty, value); }
87+
}
88+
89+
public static readonly BindableProperty LabelValueColorProperty =
90+
BindableProperty.Create(nameof(LabelValueColor), typeof(Color), typeof(MaterialSlider), defaultValue: Color.Gray);
91+
92+
public Color LabelValueColor
93+
{
94+
get { return (Color)GetValue(LabelValueColorProperty); }
95+
set { SetValue(LabelValueColorProperty, value); }
96+
}
97+
98+
public static readonly BindableProperty DisabledLabelValueColorProperty =
99+
BindableProperty.Create(nameof(DisabledLabelValueColor), typeof(Color), typeof(MaterialSlider), defaultValue: Color.Gray);
100+
101+
public Color DisabledLabelValueColor
102+
{
103+
get { return (Color)GetValue(DisabledLabelValueColorProperty); }
104+
set { SetValue(DisabledLabelValueColorProperty, value); }
105+
}
106+
107+
public static readonly BindableProperty LabelValueSizeProperty =
108+
BindableProperty.Create(nameof(LabelValueSize), typeof(double), typeof(MaterialSlider), defaultValue: Font.Default.FontSize);
109+
110+
public double LabelValueSize
111+
{
112+
get { return (double)GetValue(LabelValueSizeProperty); }
113+
set { SetValue(LabelValueSizeProperty, value); }
114+
}
115+
116+
public static readonly BindableProperty LabelValueIsVisibleProperty =
117+
BindableProperty.Create(nameof(LabelValueIsVisible), typeof(bool), typeof(MaterialSlider), defaultValue: false);
118+
119+
public bool LabelValueIsVisible
120+
{
121+
get { return (bool)GetValue(LabelValueIsVisibleProperty); }
122+
set { SetValue(LabelValueIsVisibleProperty, value); }
123+
}
124+
125+
#endregion LabelValue
126+
78127
#region LabelMinimum
79128

80129
public static readonly BindableProperty LabelMinimumTextProperty =
@@ -431,6 +480,10 @@ private void OnValueChanged(object sender, ValueChangedEventArgs e)
431480
{
432481
this.Value = e.NewValue;
433482
this.OldValue = e.OldValue;
483+
484+
if (LabelValueIsVisible)
485+
lblValue.Text = Value.ToString(LabelValueFormat);
486+
434487
ExecuteChanged();
435488
}
436489

@@ -460,6 +513,24 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
460513
case nameof(LabelSize):
461514
lblLabel.FontSize = LabelSize;
462515
break;
516+
517+
case nameof(LabelValueFormat):
518+
lblValue.Text = Value.ToString(LabelValueFormat);
519+
break;
520+
case nameof(LabelValueColor):
521+
lblValue.TextColor = LabelValueColor;
522+
break;
523+
case nameof(DisabledLabelValueColor):
524+
lblValue.TextColor = IsEnabled ? LabelValueColor : DisabledLabelValueColor;
525+
break;
526+
case nameof(LabelValueSize):
527+
lblValue.FontSize = LabelValueSize;
528+
break;
529+
case nameof(LabelValueIsVisible):
530+
lblValue.IsVisible = LabelValueIsVisible;
531+
lblValue.Text = Value.ToString(LabelValueFormat);
532+
break;
533+
463534
case nameof(LabelMinimumText):
464535
lblMinimum.Text = LabelMinimumText;
465536
lblMinimum.IsVisible = !string.IsNullOrEmpty(LabelMinimumText) && (!ShowIcons || !MinimumIconIsVisible);
@@ -614,10 +685,10 @@ public static void OnValuePropertyChanged(BindableObject bindable, object oldVal
614685

615686
public void SetEnable()
616687
{
617-
//slider.IsEnabled = IsEnabled;
618688
if(!IsEnabled)
619689
{
620690
lblLabel.TextColor = DisabledLabelTextColor;
691+
lblValue.TextColor = DisabledLabelValueColor;
621692
lblMinimum.TextColor = DisabledLabelMinimumTextColor;
622693
lblMaximum.TextColor = DisabledLabelMaximumTextColor;
623694

@@ -628,14 +699,14 @@ public void SetEnable()
628699
else
629700
{
630701
lblLabel.TextColor = LabelTextColor;
702+
lblValue.TextColor = LabelValueColor;
631703
lblMinimum.TextColor = LabelMinimumTextColor;
632704
lblMaximum.TextColor = LabelMaximumTextColor;
633705

634706
slider.ActiveTrackColor = ActiveTrackColor;
635707
slider.InactiveTrackColor = InactiveTrackColor;
636708
slider.ThumbColor = ThumbColor;
637709
}
638-
639710
}
640711

641712
#endregion Methods

0 commit comments

Comments
 (0)