Add ProgressBarRenderer
This commit is contained in:
parent
89652d8779
commit
b7d7bbfbb5
|
@ -10,6 +10,7 @@ using Xamarin.Forms.Internals;
|
||||||
[assembly: ExportRenderer (typeof (Button), typeof (ButtonRenderer))]
|
[assembly: ExportRenderer (typeof (Button), typeof (ButtonRenderer))]
|
||||||
[assembly: ExportRenderer (typeof (Entry), typeof (EntryRenderer))]
|
[assembly: ExportRenderer (typeof (Entry), typeof (EntryRenderer))]
|
||||||
[assembly: ExportRenderer (typeof (Label), typeof (LabelRenderer))]
|
[assembly: ExportRenderer (typeof (Label), typeof (LabelRenderer))]
|
||||||
|
[assembly: ExportRenderer (typeof (ProgressBar), typeof (ProgressBarRenderer))]
|
||||||
|
|
||||||
namespace Ooui.Forms
|
namespace Ooui.Forms
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Ooui.Forms.Renderers
|
||||||
|
{
|
||||||
|
public class ProgressBarRenderer : ViewRenderer<ProgressBar, Div>
|
||||||
|
{
|
||||||
|
public override SizeRequest GetDesiredSize (double widthConstraint, double heightConstraint)
|
||||||
|
{
|
||||||
|
var size = new Size (80, 20);
|
||||||
|
return new SizeRequest (size, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnElementChanged (ElementChangedEventArgs<ProgressBar> e)
|
||||||
|
{
|
||||||
|
if (e.NewElement != null) {
|
||||||
|
if (Control == null) {
|
||||||
|
var p = new Div { ClassName = "progress" };
|
||||||
|
var pb = new Div { ClassName = "progress-bar progress-bar" };
|
||||||
|
pb.SetAttribute ("role", "progressbar");
|
||||||
|
pb.SetAttribute ("aria-valuenow", "0");
|
||||||
|
pb.SetAttribute ("aria-valuemin", "0");
|
||||||
|
pb.SetAttribute ("aria-valuemax", "100");
|
||||||
|
pb.Style.Width = "0%";
|
||||||
|
p.AppendChild (pb);
|
||||||
|
SetNativeControl (p);
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateProgress ();
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnElementChanged (e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnElementPropertyChanged (sender, e);
|
||||||
|
|
||||||
|
if (e.PropertyName == ProgressBar.ProgressProperty.PropertyName)
|
||||||
|
UpdateProgress ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateProgress ()
|
||||||
|
{
|
||||||
|
var pb = Control?.Children.FirstOrDefault () as Div;
|
||||||
|
pb.Style.Width = string.Format (System.Globalization.CultureInfo.InvariantCulture, "{0}%", Element.Progress*100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@
|
||||||
<StackLayout>
|
<StackLayout>
|
||||||
<Label Text="Welcome to DisplayAlert Sample!" />
|
<Label Text="Welcome to DisplayAlert Sample!" />
|
||||||
<ActivityIndicator x:Name="activity" />
|
<ActivityIndicator x:Name="activity" />
|
||||||
|
<ProgressBar x:Name="progress" />
|
||||||
<Button Text="Tap for Display Alert"
|
<Button Text="Tap for Display Alert"
|
||||||
Clicked="OnButtonClicked" />
|
Clicked="OnButtonClicked" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
|
|
@ -17,9 +17,11 @@ namespace Samples
|
||||||
public async void OnButtonClicked(object sender, EventArgs args)
|
public async void OnButtonClicked(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
activity.IsRunning = true;
|
activity.IsRunning = true;
|
||||||
|
progress.Progress = 0.5;
|
||||||
var result = await DisplayAlert("Alert Message", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa.", "YES", "NO");
|
var result = await DisplayAlert("Alert Message", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa.", "YES", "NO");
|
||||||
await DisplayAlert("Alert Response", $"You selected value: {result}", "OK");
|
await DisplayAlert("Alert Response", $"You selected value: {result}", "OK");
|
||||||
activity.IsRunning = false;
|
activity.IsRunning = false;
|
||||||
|
progress.Progress = 1.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue