Skip to content

Commit

Permalink
added bindable property ButtonColor
Browse files Browse the repository at this point in the history
  • Loading branch information
Programming-With-Chris committed Aug 17, 2022
1 parent 78708ee commit 31e65a4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
24 changes: 21 additions & 3 deletions ShoppingList/Controls/CircularButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,30 @@ namespace ShoppingList.Controls;

public class CircularButton : GraphicsView, IGraphicsView
{
public new IDrawable Drawable { get; set; }
//public static new IDrawable Drawable { get; set; }

public Color ButtonColor
{
get => (Color?)GetValue(ButtonColorProperty);
set => SetValue(ButtonColorProperty, value);
}

public BindableProperty ButtonColorProperty = BindableProperty.Create(
nameof(ButtonColor), typeof(Color), typeof(CircularButton), propertyChanged: OnButtonColorChanged);

public CircularButton()
{
var drawable = new ShoppingList.Drawable.CircularButton();
this.Drawable = drawable;
Drawable = drawable;
}
}

static void OnButtonColorChanged(BindableObject bindable, object oldValue, object newValue)
{
var control = (CircularButton)bindable;
var buttonColor = control.ButtonColor;
var thisDrawable = control.Drawable as ShoppingList.Drawable.CircularButton;
thisDrawable.ButtonColor = buttonColor;
control.Invalidate();
}

}
4 changes: 3 additions & 1 deletion ShoppingList/Drawable/CircularButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class CircularButton : IDrawable
public int Width { get; set; } = 0;
public int Height { get; set; } = 0;

public Color ButtonColor { get; set; } = Colors.White;

public void Draw(ICanvas canvas, RectF dirtyRect)
{
canvas.StrokeColor = StrokeColor;
Expand All @@ -41,7 +43,7 @@ public void Draw(ICanvas canvas, RectF dirtyRect)
}
if (Image != null)
{
canvas.FillColor = Colors.White;
canvas.FillColor = this.ButtonColor;
canvas.FillCircle(centerOfCircle, limitingDim / 2);
canvas.DrawImage(Image, dirtyRect.X + dirtyRect.Width / 4, dirtyRect.Y + dirtyRect.Height / 4, dirtyRect.Width / 2, dirtyRect.Height / 2);
}
Expand Down
11 changes: 6 additions & 5 deletions ShoppingList/View/UserListDataInput.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@

</StackLayout>

<Button Text="Create New List"
IsEnabled="True"
Command="{Binding UserListCompletedCommand}"
Margin="8"
Grid.Row="1"/>

<Button Text="Cancel"
IsEnabled="True"
Command="{Binding CancelCommand}"
Margin="8"
Grid.Row="1"
Grid.Column="2"/>

<Button Text="Create New List"
IsEnabled="True"
Command="{Binding UserListCompletedCommand}"
Margin="8"
Grid.Row="1"/>
</Grid>


Expand Down
4 changes: 3 additions & 1 deletion ShoppingList/View/UserListDetails.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xmlns:viewmodel="clr-namespace:ShoppingList.ViewModels"
xmlns:drawables="clr-namespace:ShoppingList.Drawable"
xmlns:controls="clr-namespace:ShoppingList.Controls"
xmlns:skiasharp="clr-namespace:SkiaSharp.Extended.UI.Controls;assembly=SkiaSharp.Extended.UI"
x:DataType="viewmodel:UserListDetailViewModel"
x:Class="ShoppingList.UserListDetails"
Title="{Binding Title}">
Expand All @@ -25,6 +24,7 @@
ColumnSpacing="3"
RowDefinitions="*">

<!-- Refresh view doesn't work on iOS yet-->
<!--<RefreshView Grid.ColumnSpan="3" Command="{Binding RefreshUserListDetailScreenCommand}"
CommandParameter="UserListCollectionView"
IsRefreshing="{Binding IsRefreshing}"
Expand Down Expand Up @@ -91,6 +91,8 @@
x:Name="CircularButton"
WidthRequest="75"
HeightRequest="75"
Margin="15,0,0,0"
ButtonColor="{StaticResource Primary}"
BackgroundColor="Transparent"
VerticalOptions="End"
HorizontalOptions="Start"
Expand Down

0 comments on commit 31e65a4

Please sign in to comment.