-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Created RoundImageEx, Moved ImageEx Core Logic to Base Class #1100
Conversation
…ipped Image. -Moved shared ImageEx Logic to ImageEx base. -RoundImageEx has Properties to add Stroke, StrokeThickness and the ability to disable Stroke on Placeholder Images. -Added RoundImageEx to ImageEx Sample Page.
-Removed Unused Usings.
@WilliamABradley, It will cover your contributions to all .NET Foundation-managed open source projects. |
@WilliamABradley, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request. |
-Moved Stroke Visual State Strings to RoundImageEx. -Attached PlaceholderSourceChanged (Woops) and removed SetSource as it was copied from ImageEx.Source. -ShowStroke Visual State doesn't seem to work, testing the Stroke animation with EnableDependentAnimation works on the CommonStates, but not in StrokeStates, so I am temporarily setting StrokeThickness binding (ShowPlaceholderStroke does nothting).
It all works except for the View State to show StrokeThickness on the Placeholder Image. Currently I have just set the StrokeThickness to the Placeholder Image, so the ShowPlaceholderStroke bool does nothing. |
…t properties now work. -Modified coding formatting to adhere to Style requests. -Fixed missing Bracket.
@WilliamABradley I think something has wrong very wrong. Another PR is being referenced. That way you need to do is that the 2nd PR must start on dev again |
@hermitdave How do you mean? This one was on the dev branch, but I wanted to create a second PR, but it wouldn't let me take a branch off of Microsoft/Dev, so I branched off of Origin/Dev and reverted the changes. How do I fix this mess?
|
maybe I didn't pay enough attention.. it however looks to me that there are conflicts for |
@hermitdave I shifted the Core Logic out of ImageEx into a base class so that a RoundImageEx class can use the shared Logic. (The ImageBrush and Image implementations are different, so an XAML restyle wouldn't work here). ImageEx gets to retain all of it's functionality, and RoundImageEx gets to use ImageCache and most of the features of ImageEx, except it loses Nine Grid and GetAsCasting source, but you can use it to create circular images, which ImageEx can't do. |
@hermitdave I Merged back onto Microsoft/Dev if that helps? |
@WilliamABradley you need to run Please run '.\build.ps1 UpdateHeaders' from powershell to fix issue with file headers. I have reviewed much of the code yesterday. Will go through again over the weekend |
@hermitdave I'm getting this issue. Is it compatible with VS 2017? Or do I need something else? Do I need to specify a path parameter? |
|
||
if (e.OldValue == null || e.NewValue == null || !e.OldValue.Equals(e.NewValue)) | ||
{ | ||
if (control is RoundImageEx round) |
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.
From what I know, C# 7 is not currently available for Continuous Integration. Please change to use C# 6 features such as as
.
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.
:( I looked it up and I couldn't find anything about it? It is located in quite a bit of my code, in this and in #1116, so it would be a pain to replace.
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.
@WilliamABradley If you want us to merge your branch, I recommend you to retarget your code to C# 6 only. To clarify, I am not against C# 7 but the fact is that the solution will not compile because CI does not support C# 7 for the moment.
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.
think you might be better off with something like this
RoundImageEx round = control as RoundImageEx
if (round != null)
{
}
else
{
}
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.
@Odonno Fixed it, I'll do the same for my other PR.
…nt, as it caused a RuntimeBinder Exception in .Net Native.
@Odonno @hermitdave I have replaced the C# 7 features with C# 6 compatible features. I have also fixed an issue that caused a crash in .Net Native. I believe that this PR is ready for final review, as it is also now passing in AppVeyor :) |
@Odonno What happens now? |
A PR requires 2 reviews, I'll do mine maybe tonight. If all is well, i will merge it in |
@hermitdave Awesome! When I get around to it, I also have a few more things I could contribute, such as:
|
@WilliamABradley create issues and uservoice entries for those. As far as adaptive grid like control, maybe providing that as an option within AdaptiveGridView might be desirable. |
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
using Windows.Media.Casting; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; |
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.
usings should be outside of the namespace
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
using System; | ||
using Windows.UI.Xaml; |
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.
usings outside of namespace
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
using Windows.UI.Xaml; |
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.
usings outside namespace
|
||
if (e.OldValue == null || e.NewValue == null || !e.OldValue.Equals(e.NewValue)) | ||
{ | ||
RoundImageEx round = control as RoundImageEx; |
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.
Discussion: There should be a virtual OnPlaceholderSourceChanged method that RoundImageEx can override and all this code should go in there, rather than be in the base class.
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; |
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.
usings outside namespace
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
using System; |
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.
usings outside namespace
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
using System; |
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.
usings outside namespace
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Media; |
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.
usings outside namespace
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Media; |
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.
usings outside namespace
@@ -0,0 +1,125 @@ | |||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
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.
Ensure xaml styler has been run on this.
-Made OnPlaceholdersource changed, marked virtual to be overridden. -ShowPlaceholderStroke still disabled as ViewState doesn't work.
@ScottIsAFool Those changes have been made, however, |
@WilliamABradley you can't have a binding in the To value when used inside a control template. This would have to be set in code, sadly. |
@ScottIsAFool How would that be done? Would you attach an x:Name to the Animation so you update the value when the StrokeThickness changes, or some other way? |
@WilliamABradley to be honest, looking at it, I'm not sure any of that is needed. Your ellipse's StrokeThickness is already being set and that should suffice. I don't think the ShowPlaceholderStroke property is even needed. I'm going to add a couple more comments to my review. |
HorizontalAlignment="{TemplateBinding HorizontalAlignment}" | ||
VerticalAlignment="{TemplateBinding VerticalAlignment}" | ||
Opacity="1.0" | ||
Stroke="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Stroke}" |
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.
This should just be a TemplateBinding
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.
This is due to a bug in ImageBrushes http://stackoverflow.com/questions/22134281/templatebinding-fails-when-the-target-is-an-imagebrush-imagesource
VerticalAlignment="{TemplateBinding VerticalAlignment}" | ||
Opacity="1.0" | ||
Stroke="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Stroke}" | ||
StrokeThickness="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=StrokeThickness}"> |
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.
This should also just be a TemplateBinding
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.
This is due to a bug in ImageBrushes http://stackoverflow.com/questions/22134281/templatebinding-fails-when-the-target-is-an-imagebrush-imagesource
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.
I'm not sure this is applicable. From what that SO says, this is because the OP needed to basically convert to another value. As long as Stroke and StrokeThickness on RoundImageEx are using the same property types as Ellipse, then no conversion should be needed and TemplateBinding can be used.
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.
Woops, It was only for the ImageBrushes anyway, not the Properties on the Ellipse.
</VisualState> | ||
<VisualState x:Name="Unloaded" /> | ||
</VisualStateGroup> | ||
<VisualStateGroup x:Name="StrokeStates"> |
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.
I'm not sure this VisualState is even needed.
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.
DependencyProperty.Register(nameof(StrokeProperty), typeof(Brush), typeof(RoundImageEx), new PropertyMetadata(default(Brush))); | ||
|
||
// Using a DependencyProperty as the backing store for ShowPlaceholderStroke. This enables animation, styling, binding, etc... | ||
public static readonly DependencyProperty ShowPlaceholderStrokeProperty = |
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.
Is this property even needed? If the dev doesn't want the placeholder to have a stroke, then the StrokeThickness should just be set to 0.
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.
Makes sense
{ | ||
// Using a DependencyProperty as the backing store for StrokeThickness. This enables animation, styling, binding, etc... | ||
public static readonly DependencyProperty StrokeThicknessProperty = | ||
DependencyProperty.Register(nameof(StrokeThickness), typeof(double), typeof(RoundImageEx), new PropertyMetadata(default(double))); |
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.
This property should really be using Thickness, not double as its type.
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.
The StrokeThickness on an Ellipse is a double Property, this is just a pass-through. It wouldn't make sense for a circle to have differing thickness on different sides. It has no sides,
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.
Interesting, ignore this. Apparently for Ellipse StrokeThickness uses double, not Thickness, like everywhere else does 8-)
-Fixed StrokeProperty. -Replaced Bindings with TemplateBindings for Stroke and Thickness for Ellipses.
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.
Looks great.
Only request I have is about documentation. The sample page should be more clear that these are two different controls. At minimum, the code should have code for both controls.
Also, could you update the documentation for ImageEx to include this control?
<Setter.Value> | ||
<ControlTemplate TargetType="controls:RoundImageEx"> | ||
<Grid> | ||
<Ellipse x:Name="PlaceholderEllipse" |
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.
I know its a bit late in the day. Any reason we are using Ellipse instead of Border ? Border would allow you to have image with rounded corner rather than elliptical images which is what default will be unless the user were to go override the XAML.
Personally Image with CornerRadius better than PeoplePicture (the one coming out in FCU)
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.
I guess that could work too, because you could set the corner radius to say 999, in order to create a round image anyway right?
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.
Its not difficult to create rounded image by tweaking corner radius. I am not sure if there's a default value that forces circular ellipse but my point is Border with RoundedCorner can be turned into fully circular image if desired.
Ellipse can't do that. Any thoughts on why we should go for one or the other ?
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.
The Control name wouldn't make sense anymore. I could name it ImageBrushEx, although it would still be encapsulated so it wouldn't really be an ImageBrush you could attach to things,
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.
good point about naming. @nmetulev @ScottIsAFool @Odonno any thoughts on this ?
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.
Another thing is, without setting the corner radius, it behaves practically the same as ImageEx, but without NineGrid
and GetAsCastingSource
…rnerRadius as a larger number, e.g. 999. -Setting Stroke is replaced with Setting BorderBrush and BorderThickness. -Added RoundImageEx to ImageEx.md, as well as to the .bind file.
@nmetulev I have updated the documentation. |
Thanks :) |
I was looking for a way to clip an
ImageEx
Control, then I stumbled on to #277 where @JohnnyWestlake suggested restructuring theImageEx
to useImageBrush
es, but didn't want to because it would remove features.He wanted to have the Original ImageEx Logic and I wanted the ability to make a Circular Image.
I thought, Why don't we have both?
Da, Da Da, Da Da, Da.
I shifted all of the Core Logic to the
ImageExBase
Base Class,ImageEx
retains complete original functionality, and I created the newRoundImageEx
to useEllipse
s andImageBrush
es.RoundImageEx
losesGetAsCastingSource()
&NineGrid
, however, it gains the ability to add aStroke
w/StrokeThickness
& the ability to disable Stroke on Placeholder Images.I also updated the ImageEx Sample Page, although it doesn't demonstrate using Stroke, or other
RoundImageEx
properties.