[Proposal] Add `IImage` Extension Methods
brminnick opened this issue · 4 comments
brminnick commented
Add IImage
Extension Methods
- Proposed
- Prototype
- Implementation
- iOS Support
- Android Support
- macOS Support
- Windows Support
- Unit Tests
- Sample
- Documentation MicrosoftDocs/CommunityToolkit#49
Link to Discussion
Summary
This Proposal adds the following fluent extension methods for IImage
:
public static TBindable Source<TBindable>(this TBindable bindable, ImageSource imageSource) where TBindable : BindableObject, IImageSourcePart;
public static TBindable Aspect<TBindable>(this TBindable bindable, Aspect aspect) where TBindable : BindableObject, IImage;
public static TBindable IsOpaque<TBindable>(this TBindable bindable, bool isOpaque) where TBindable : BindableObject, IImage;
Motivation
Currently, the only way to assign values on an Image
is to set the property directly, like so:
var image = new Image { Source = "dotnetbot", IsOpaque = true, Aspect = Aspect.AspectFill };
This Proposal allows us to instead assign these values using the fluent C# Markup syntax.
Detailed Design
public static TBindable Source<TBindable>(this TBindable bindable, ImageSource imageSource) where TBindable : BindableObject, IImageSourcePart
{
bindable.SetValue(ImageElement.SourceProperty, imageSource);
return bindable;
}
public static TBindable Aspect<TBindable>(this TBindable bindable, Aspect aspect) where TBindable : BindableObject, IImage
{
bindable.SetValue(ImageElement.AspectProperty, aspect);
return bindable;
}
public static TBindable IsOpaque<TBindable>(this TBindable bindable, bool isOpaque) where TBindable : BindableObject, IImage
{
bindable.SetValue(ImageElement.IsOpaqueProperty, isOpaque);
return bindable;
}
Usage Syntax
C# Usage
Content = new Image().Source("dotnetbot").Aspect(Aspect.AspectFill).IsOpaque(true);
Drawbacks
No known drawbacks
Alternatives
The current alternative is to assign the properties upon initialization:
var image = new Image { Source = "dotnetbot", IsOpaque = true, Aspect = Aspect.AspectFill };
Unresolved Questions
No unresolved questions
pictos commented
I approve this feature ✅
VladislavAntonyuk commented
Approve
brminnick commented
I also approve ✅
Deleted user commented
Reopening Proposal.
Only Proposals moved to the Closed
Project Column and Completed
Project Column can be closed.