-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
ImageButtonHandler and Handler Re-usability #2352
Changes from 7 commits
4cfdf62
f1f6b27
70e4940
39dac1d
8a39390
d1f4c35
abc7e91
879524d
b0206bb
b06cfc3
99820ef
32638d3
f6e79d3
b34cd9b
9c36b7d
b2fc8a1
f2502fc
bf7fd1d
f9bc413
c095292
c1f3d0d
b6f0781
3af5f1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<views:BasePage | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Pages.ImageButtonPage" | ||
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base" | ||
Title="ImageButton"> | ||
<views:BasePage.Content> | ||
<VerticalStackLayout Margin="12" Spacing="6"> | ||
<Label | ||
Text="AspectFit" | ||
Style="{StaticResource Headline}"/> | ||
<ImageButton HorizontalOptions="Center" WidthRequest="200" HeightRequest="100" Clicked="OnImageButtonClicked" Aspect="AspectFit" Background="Green" Source="settings.png" Padding="16, 9, 16, 9" /> | ||
<Label | ||
Text="AspectFill" | ||
Style="{StaticResource Headline}"/> | ||
<ImageButton HorizontalOptions="Center" WidthRequest="200" HeightRequest="100" Clicked="OnImageButtonClicked" Aspect="AspectFill" Background="Green" Source="settings.png" Padding="16, 9, 16, 9" /> | ||
<Label | ||
Text="Fill" | ||
Style="{StaticResource Headline}"/> | ||
<ImageButton HorizontalOptions="Center" WidthRequest="200" HeightRequest="100" Clicked="OnImageButtonClicked" Aspect="Fill" Background="Green" Source="settings.png" Padding="16, 9, 16, 9" /> | ||
<Label | ||
x:Name="InfoLabel" | ||
Text="0 ImageButton clicks" | ||
FontSize="16" | ||
HorizontalOptions="Center" | ||
VerticalOptions="CenterAndExpand" /> | ||
</VerticalStackLayout> | ||
</views:BasePage.Content> | ||
</views:BasePage> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Microsoft.Maui.Controls | ||
{ | ||
public partial class ImageButton : IImageButton | ||
{ | ||
void IImageSourcePart.UpdateIsLoading(bool isLoading) { } | ||
|
||
bool IImageSourcePart.IsAnimationPlaying => false; | ||
|
||
IImageSource IImageSourcePart.Source => Source; | ||
|
||
void IButton.Clicked() | ||
{ | ||
(this as IButtonController).SendClicked(); | ||
} | ||
|
||
void IButton.Pressed() | ||
{ | ||
(this as IButtonController).SendPressed(); | ||
} | ||
|
||
void IButton.Released() | ||
{ | ||
(this as IButtonController).SendReleased(); | ||
} | ||
|
||
void IButton.ImageSourceLoaded() | ||
{ | ||
} | ||
|
||
IImageSourcePart IButton.ImageSource => this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
namespace Microsoft.Maui.Controls | ||
{ | ||
public class MenuItem : BaseMenuItem, IMenuItemController, IStyleSelectable, IImageSourcePart | ||
public class MenuItem : BaseMenuItem, IMenuItemController, IStyleSelectable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new |
||
{ | ||
public static readonly BindableProperty AcceleratorProperty = BindableProperty.CreateAttached(nameof(Accelerator), typeof(Accelerator), typeof(MenuItem), null); | ||
|
||
|
@@ -141,16 +141,5 @@ void OnCommandParameterChanged() | |
|
||
IsEnabledCore = Command.CanExecute(CommandParameter); | ||
} | ||
|
||
|
||
IImageSource IImageSourcePart.Source => this.IconImageSource; | ||
|
||
bool _isLoading; | ||
bool IImageSourcePart.IsAnimationPlaying => false; | ||
|
||
void IImageSourcePart.UpdateIsLoading(bool isLoading) | ||
{ | ||
_isLoading = isLoading; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,16 +167,10 @@ void clickCallback(object s, EventArgs e) | |
|
||
image.ImageTintList = ColorStateList.ValueOf(Colors.Black.MultiplyAlpha(0.6f).ToNative()); | ||
|
||
ImageSourceLoader shellImagePart = new ImageSourceLoader() | ||
shellContent.icon.LoadImage(mauiContext, result => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the changes involving |
||
{ | ||
Source = shellContent.icon | ||
}; | ||
|
||
|
||
var services = mauiContext.Services; | ||
var provider = services.GetRequiredService<IImageSourceServiceProvider>(); | ||
image.UpdateSourceAsync(new ImageSourceLoader() { Source = shellContent.icon }, provider) | ||
.FireAndForget(e => Internals.Log.Warning("MenuItem", $"{e}")); | ||
image.SetImageDrawable(result.Value); | ||
}); | ||
|
||
innerLayout.AddView(image); | ||
|
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
IText
fromIButton
becauseButton
might not be aText
based button.