Skip to content

Instantly share code, notes, and snippets.

@yavor87
Last active January 22, 2019 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yavor87/7b956984a36835536d724d4d03b115bc to your computer and use it in GitHub Desktop.
Save yavor87/7b956984a36835536d724d4d03b115bc to your computer and use it in GitHub Desktop.
<ContentView
<ContentView.ControlTemplate>
<ControlTemplate>
<telerikPrimitives:RadBorder CornerRadius="2" BackgroundColor="{TemplateBinding BackgroundColor}">
<Grid Margin="{TemplateBinding Padding}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Text="{TemplateBinding Title}" FontSize="Large" />
<ContentPresenter Grid.Row="1" Margin="0,10" />
<StackLayout Grid.Row="2" Orientation="Horizontal" HorizontalOptions="End">
<telerikInput:RadButton Text="Cancel" Clicked="OnCancel" />
<telerikInput:RadButton Text="OK" Clicked="OnAccept" />
</StackLayout>
</Grid>
</telerikPrimitives:RadBorder>
</ControlTemplate>
</ContentView.ControlTemplate>
</ContentView>
public partial class ContentDialog : ContentView
{
public static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title),
typeof(string),
typeof(ContentDialog));
public event Action<bool> Closed;
public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
private void OnAccept(object sender, EventArgs e)
{
Closed?.Invoke(true);
}
private void OnCancel(object sender, EventArgs e)
{
Closed?.Invoke(false);
}
}
<Grid>
<telerikPrimitives:RadPopup.Popup>
<telerikPrimitives:RadPopup x:Name="popup" IsModal="True" Placement="Center" OutsideBackgroundColor="#6F000000">
<local:ContentDialog Title="Please select a color" Padding="20" BackgroundColor="White" Closed="OnDialogClosed">
<Grid>
<Label Text="Red:" Grid.Row="0" Grid.Column="0" VerticalOptions="Center" />
<Slider x:Name="redSlider" Grid.Row="0" Grid.Column="1" VerticalOptions="Center"
Minimum="0" Maximum="255" />
<Label Text="Green:" Grid.Row="1" Grid.Column="0" VerticalOptions="Center" />
<Slider x:Name="greenSlider" Grid.Row="1" Grid.Column="1" VerticalOptions="Center"
Minimum="0" Maximum="255" />
<Label Text="Blue:" Grid.Row="2" Grid.Column="0" VerticalOptions="Center" />
<Slider x:Name="blueSlider" Grid.Row="2" Grid.Column="1" VerticalOptions="Center"
Minimum="0" Maximum="255" />
</Grid>
</local:ContentDialog>
</telerikPrimitives:RadPopup>
</telerikPrimitives:RadPopup.Popup>
<BoxView x:Name="box" WidthRequest="100" HeightRequest="100" HorizontalOptions="Center" VerticalOptions="Center" Color="Accent" />
<Button Text="Select color" VerticalOptions="Center" Margin="20,140,20,0" Clicked="SelectColor" />
</Grid>
private void SelectColor(object sender, EventArgs e)
{
SetColor(box.Color);
popup.IsOpen = true;
}
private void OnDialogClosed(bool accepted)
{
popup.IsOpen = false;
if (accepted)
box.Color = GetColor();
}
public Color GetColor()
{
return Color.FromRgb(this.redSlider.Value / 255, this.greenSlider.Value / 255, this.blueSlider.Value / 255);
}
public void SetColor(Color color)
{
this.redSlider.Value = color.R * 255;
this.greenSlider.Value = color.G * 255;
this.blueSlider.Value = color.B * 255;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment