This repository was archived by the owner on Apr 3, 2023. It is now read-only.
Open
Conversation
| @@ -0,0 +1,8 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
There was a problem hiding this comment.
I suggest you to use PackageReference
| return; | ||
|
|
||
| file = Element.Source; | ||
|
|
There was a problem hiding this comment.
IImageSourceHandler handler;
switch (file)
{
case UriImageSource _:
handler = new UriImageSourceHandler();
break;
case FileImageSource f:
if(!File.Exists(f.File))
{
return;
}
handler = new FileImageSourceHandler();
break;
case StreamImageSource _:
handler = new StreamImageSourceHandler();
break;
default:
return;
}
| return; | ||
| } | ||
|
|
||
| if (bitmapImage != null) |
There was a problem hiding this comment.
var originalBitmap = await handler.LoadImageAsync(Element.Source);
if (originalBitmap != null)
{
Control.Fill = new ImageBrush
{
ImageSource = originalBitmap,
Stretch = Stretch.UniformToFill
};
}
| /// <summary> | ||
| /// ImageCircle Implementation | ||
| /// </summary> | ||
| public class ImageCircleRenderer : ViewRenderer<Image, Ellipse> |
There was a problem hiding this comment.
I have changed a code for this file:
private ImageSource file;
protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
var ellipse = new Ellipse();
SetNativeControl(ellipse);
}
}
protected override async void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (Control == null)
{
return;
}
var min = Math.Min(Element.Width, Element.Height);
if (min / 2.0f <= 0)
{
return;
}
Control.Width = min;
Control.Height = min;
// Fill background color
var color = ((CircleImage) Element).FillColor;
Control.Fill = XamarinColorToBrush(color);
// Fill stroke
color = ((CircleImage) Element).BorderColor;
Control.StrokeThickness = ((CircleImage) Element).BorderThickness;
Control.Stroke = XamarinColorToBrush(color);
var force = ForceUpdate(e.PropertyName);
//already set
if (file == Element.Source && !force)
{
return;
}
file = Element.Source;
IImageSourceHandler handler;
switch (file)
{
case UriImageSource _:
handler = new UriImageSourceHandler();
break;
case FileImageSource f:
if(!File.Exists(f.File))
{
return;
}
handler = new FileImageSourceHandler();
break;
case StreamImageSource _:
handler = new StreamImageSourceHandler();
break;
default:
return;
}
var originalBitmap = await handler.LoadImageAsync(Element.Source);
if (originalBitmap != null)
{
Control.Fill = new ImageBrush
{
ImageSource = originalBitmap,
Stretch = Stretch.UniformToFill
};
}
}
private static bool ForceUpdate(string propertyName)
{
var forcePropertiesList = new List<string>
{
VisualElement.XProperty.PropertyName,
VisualElement.YProperty.PropertyName,
VisualElement.WidthProperty.PropertyName,
VisualElement.HeightProperty.PropertyName,
VisualElement.ScaleProperty.PropertyName,
VisualElement.TranslationXProperty.PropertyName,
VisualElement.TranslationYProperty.PropertyName,
VisualElement.RotationYProperty.PropertyName,
VisualElement.RotationXProperty.PropertyName,
VisualElement.RotationProperty.PropertyName,
CircleImage.BorderThicknessProperty.PropertyName,
CircleImage.BorderColorProperty.PropertyName,
CircleImage.FillColorProperty.PropertyName,
VisualElement.AnchorXProperty.PropertyName,
VisualElement.AnchorYProperty.PropertyName
};
return forcePropertiesList.Contains(propertyName);
}
private static Brush XamarinColorToBrush(Color color)
{
return new SolidColorBrush(System.Windows.Media.Color.FromArgb(
(byte) (color.A * 255),
(byte) (color.R * 255),
(byte) (color.G * 255),
(byte) (color.B * 255)));
}
| /// Used for registration with dependency service | ||
| /// </summary> | ||
| public async static void Init() | ||
| #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously |
There was a problem hiding this comment.
Init is not necessary, I suggest to replace the file with the code above
| Stretch = Stretch.UniformToFill | ||
| }; | ||
| } | ||
| catch |
There was a problem hiding this comment.
try catch looks uninformative, you can remove it
VladislavAntonyuk
suggested changes
Feb 23, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I used the code of @VladislavAntonyuk, it worked and I applied here