* SliderRenderer.Value/Minimum/Maximum are treated as a fixed point value. (1/100)
This commit is contained in:
aosoft 2018-02-08 23:19:27 +09:00
Родитель 6b64b53dd7
Коммит b6cb512430
5 изменённых файлов: 53 добавлений и 13 удалений

Просмотреть файл

@ -8,6 +8,14 @@
BackgroundColor="Yellow"
CornerRadius="8">
<Image Source="https://assets-cdn.github.com/images/modules/logos_page/GitHub-Logo.png" Aspect="AspectFill"/>
<!--<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ProgressBar Grid.Row="0" Progress="{Binding Source={x:Reference slider}, Path=Value}" />
<Slider Grid.Row="1" Value="0" Minimum="0" Maximum="1" x:Name="slider" />
</Grid>-->
</Frame>
</ContentPage.Content>
</ContentPage>

Просмотреть файл

@ -54,6 +54,7 @@ using Xamarin.Forms.Platform.WinForms;
[assembly: ExportRenderer(typeof(DatePicker), typeof(DatePickerRenderer))]
[assembly: ExportRenderer(typeof(Frame), typeof(FrameRenderer))]
[assembly: ExportRenderer(typeof(Image), typeof(ImageRenderer))]
[assembly: ExportRenderer(typeof(ProgressBar), typeof(ProgressBarRenderer))]
[assembly: ExportRenderer(typeof(OpenGLView), typeof(OpenGLViewRenderer))]
[assembly: ExportRenderer(typeof(WebView), typeof(WebViewRenderer))]

Просмотреть файл

@ -0,0 +1,37 @@
using System;
using System.ComponentModel;
using WForms = System.Windows.Forms;
namespace Xamarin.Forms.Platform.WinForms
{
public class ProgressBarRenderer : ViewRenderer<ProgressBar, WForms.ProgressBar>
{
protected override void OnElementChanged(ElementChangedEventArgs<ProgressBar> e)
{
if (e.NewElement != null)
{
if (Control == null)
{
SetNativeControl(new WForms.ProgressBar { Minimum = 0, Maximum = 100 });
}
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()
{
UpdatePropertyHelper((element, control) => control.Value = (int)(element.Progress * 100.0));
}
}
}

Просмотреть файл

@ -6,6 +6,8 @@ namespace Xamarin.Forms.Platform.WinForms
{
public class SliderRenderer : ViewRenderer<Slider, WForms.TrackBar>
{
public static readonly int Scale = 100;
/*-----------------------------------------------------------------*/
#region Event Handler
@ -56,7 +58,7 @@ namespace Xamarin.Forms.Platform.WinForms
void OnValueChanged(object sender, EventArgs e)
{
((IElementController)Element).SetValueFromRenderer(Slider.ValueProperty, Control.Value);
((IElementController)Element).SetValueFromRenderer(Slider.ValueProperty, (double)Control.Value / Scale);
}
@ -67,26 +69,17 @@ namespace Xamarin.Forms.Platform.WinForms
void UpdateValue()
{
if (Control != null && Element != null)
{
Control.Value = (int)Element.Value;
}
UpdatePropertyHelper((element, control) => control.Value = (int)(element.Value * Scale));
}
void UpdateMinimum()
{
if (Control != null && Element != null)
{
Control.Minimum = (int)Element.Minimum;
}
UpdatePropertyHelper((element, control) => control.Minimum = (int)(element.Minimum * Scale));
}
void UpdateMaximum()
{
if (Control != null && Element != null)
{
Control.Maximum = (int)Element.Maximum;
}
UpdatePropertyHelper((element, control) => control.Maximum = (int)(element.Maximum * Scale));
}
#endregion

Просмотреть файл

@ -80,6 +80,7 @@
<Compile Include="Renderers\PageRenderer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderers\PickerRenderer.cs" />
<Compile Include="Renderers\ProgressBarRenderer.cs" />
<Compile Include="Renderers\SliderRenderer.cs" />
<Compile Include="Renderers\StepperRenderer.cs" />
<Compile Include="Renderers\SwitchRenderer.cs" />