Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maui Advanced Slider #242

Merged
merged 2 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
// );
}
}