Skip to content

Commit

Permalink
Merge pull request #242 from enisn/maui/advanced-slider
Browse files Browse the repository at this point in the history
Maui Advanced Slider
  • Loading branch information
enisn authored Mar 12, 2022
2 parents 1fafa8f + 736ff42 commit 4633e91
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 18 deletions.
1 change: 1 addition & 0 deletions sandbox/SandboxMAUI/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Button Text="Radio Button" Clicked="GoToRadioButtonPage" />

<Button Text="Advanced Entry &amp; FormView" Clicked="GoToAdvancedEntryPage" />
<Button Text="Advanced Slider" Clicked="GoToAdvancedSliderPage" />

</StackLayout>
</ScrollView>
Expand Down
31 changes: 18 additions & 13 deletions sandbox/SandboxMAUI/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@

namespace SandboxMAUI
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}

async void GoToCheckBoxPage(System.Object sender, System.EventArgs e)
{
await Navigation.PushAsync(new CheckBoxPage());
await Navigation.PushAsync(new CheckBoxPage());
}

async void GoToRadioButtonPage(System.Object sender, System.EventArgs e)
{
await Navigation.PushAsync(new RadioButtonPage());
}
{
await Navigation.PushAsync(new RadioButtonPage());
}

async void GoToAdvancedEntryPage(System.Object sender, System.EventArgs e)
{
await Navigation.PushAsync(new AdvancedEntryPage());
}
{
await Navigation.PushAsync(new AdvancedEntryPage());
}

async void GoToAdvancedSliderPage(System.Object sender, System.EventArgs e)
{
await Navigation.PushAsync(new AdvancedSliderPage());
}
}
}
20 changes: 20 additions & 0 deletions sandbox/SandboxMAUI/Pages/AdvancedSliderPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:input="clr-namespace:InputKit.Shared.Controls;assembly=InputKit"
x:Class="SandboxMAUI.Pages.AdvancedSliderPage"
Title="AdvancedSliderPage">
<ScrollView>
<StackLayout Padding="25" Spacing="15">

<input:AdvancedSlider MaxValue="5000"
MinValue="50"
StepValue="50"
Value="{Binding Price}"
ValuePrefix="Offer:"
ValueSuffix="$"
Title="Choose Budget:"/>

</StackLayout>
</ScrollView>
</ContentPage>
11 changes: 11 additions & 0 deletions sandbox/SandboxMAUI/Pages/AdvancedSliderPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Maui.Controls;

namespace SandboxMAUI.Pages;

public partial class AdvancedSliderPage : ContentPage
{
public AdvancedSliderPage()
{
InitializeComponent();
}
}
17 changes: 12 additions & 5 deletions src/InputKit/Shared/Controls/AdvancedSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,17 @@ void UpdateView()
{
var totalLength = MaxValue - MinValue;
var normalizedValue = Value - MinValue;
lblValue.TranslateTo(
normalizedValue * ((slider.Width - 30) / totalLength), //pos X /* -30 is used to make smaller label horizontal movable region and prevent touching minValue and maxValue labels*/
slider.TranslationY - lblValue.Height * 0.9, //pos Y
40 //Latency
);


// TODO: Keep animation disabled until resolution of https://github.com/dotnet/maui/issues/3353

lblValue.TranslationX = normalizedValue * ((slider.Width - 30) / totalLength);
lblValue.TranslationY = slider.TranslationY - lblValue.Height * 0.9;

//lblValue.TranslateTo(
// normalizedValue * ((slider.Width - 30) / totalLength), //pos X /* -30 is used to make smaller label horizontal movable region and prevent touching minValue and maxValue labels*/
// slider.TranslationY - lblValue.Height * 0.9, //pos Y
// 40 //Latency
// );
}
}

0 comments on commit 4633e91

Please sign in to comment.