These are chat archives for JohanLarsson/Gu.Wpf.PropertyGrid

7th
Jul 2016
Johan Larsson
@JohanLarsson
Jul 07 2016 17:30
@bloritsch deleted the old room, was some old repo I didn't know I had :)
Berin Loritsch
@bloritsch
Jul 07 2016 21:33
So is this for the propertygrid project or that smaller one?
Berin Loritsch
@bloritsch
Jul 07 2016 21:55
So with the GenericControlBox project I'm seeing something you can do with your style that prevents having to restyle everything just to change a color.
Johan Larsson
@JohanLarsson
Jul 07 2016 21:56
yeah
question is, is it worth using
it is a hack
Berin Loritsch
@bloritsch
Jul 07 2016 21:56
Perhaps if you gave me some background on the problem you are trying to solve?
Johan Larsson
@JohanLarsson
Jul 07 2016 21:58
The most urgent problem is the nasty duplication here
No problem generating it but restyling in an app would be a massive pain.
and the need for setting targettype to a generic type comes up every now and then ime
Berin Loritsch
@bloritsch
Jul 07 2016 22:00
OK. The basic problem of double vs. int could easily be handled similarly to how the Slider control works.
The bound value is still a double but the "IsSnapToTickEnabled" boolean property lets you coerce the values to denominations you want.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:02
yeah
I used double vs int as they are familiar
Berin Loritsch
@bloritsch
Jul 07 2016 22:02
I guess a better name would be IsRoundToIntEnabled
Johan Larsson
@JohanLarsson
Jul 07 2016 22:04
out of curiosity, you never had the need to constrain a style or template to a generic type?
Berin Loritsch
@bloritsch
Jul 07 2016 22:04
Important stuff for templates is to use {TemplateBinding} for a lot of the properties you would expect to manipulate, like Foreground, Background, etc. Which makes them a bit more flexible
Constraining a style to a type? not really.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:05
oh, I mean setting targettype
Berin Loritsch
@bloritsch
Jul 07 2016 22:05
Ah, I always set TargetType for styles.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:06
yeah but never had a situation where setting it to an open generic type would have made sense?
Berin Loritsch
@bloritsch
Jul 07 2016 22:06
The key is to make the underlying control smart enough to allow users to supply specific DataTemplates to format just their data.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:07
yeah, using contentpresenters and datatemplateselector is an option
I'm optimizing a bit for shallow visual tree
Berin Loritsch
@bloritsch
Jul 07 2016 22:08
Understandable.
They do have a significant performance penalty if not kept in check
Johan Larsson
@JohanLarsson
Jul 07 2016 22:08
wrote a ControlTemplateSelector bt not gonna use it for the default stuff
as it is nonstandard and making the api a bit harder
Berin Loritsch
@bloritsch
Jul 07 2016 22:09
Yeah, reasonable defaults are always good.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:11
about the small prototype thing: I spent some time thinking about where it will break but could not figure out any edge cases
still have a feeling it is broken as one can't really win vs wpf :D
Berin Loritsch
@bloritsch
Jul 07 2016 22:12
The easy one would be code-behind referencing the NumberControl.
If it changes the Value it will throw an exception
Those new declarations leave ugly holes like that.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:13
yeah, we are somewhat protected from that with internal
and fail fast, but I agree it is a hack
maybe [EditorBrowsable(never)] could help but I'm not sure I have ever seen it do anything
Berin Loritsch
@bloritsch
Jul 07 2016 22:14
The property for Value could be IFormattable (which includes ints, doubles, etc.) and then provide a type specific coerce function
[EditorBrowsable] is supposed to only affect VS designer.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:15
yeah, wrote that first but was not happy with it
protected abstract Coerce(object)
but maybe it is cleaner
Berin Loritsch
@bloritsch
Jul 07 2016 22:16
So, back to the style duplication issue, there's a couple tricks that you can employ:
Johan Larsson
@JohanLarsson
Jul 07 2016 22:16
were some issues with setting the value in xaml then but probably workaroundable
Berin Loritsch
@bloritsch
Jul 07 2016 22:17
If your x:Key={x:Type BaseControl} and TargetType=BaseControl, then any subclass of that base control will adopt that base style
That is, until you override the style explicitly
I think the closest problem I had to what you are dealing with was a tree view for configuration items. So we had a base class for most of the functionality.
We were happy to discover that the style conveyed to every subclass.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:20
yeah, that works as long as BaseControl is not a generic type
Johan Larsson
@JohanLarsson
Jul 07 2016 22:22
nope not that one but played around a bit with custom markupextensions today
untested but I think it needs to be: {x:Type 'local:View`1'}
is that you asking?
Berin Loritsch
@bloritsch
Jul 07 2016 22:26
A lot of the value coercion happens based on what you bind to. For example, binding a TextBox to a double restricts it to what can fit in a double. I'm having a hard time with a WPF control needing to be generic personally.
The code it's bound to, absolutely. But the control itself I'm trying to envision why I would want to do that.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:27
maybe it is just me obsessing about types :)
and compiletime safety
Berin Loritsch
@bloritsch
Jul 07 2016 22:27
Trying to use a precision screwdriver where a hammer is better :)
Johan Larsson
@JohanLarsson
Jul 07 2016 22:28
yeah, wpf uses the hammer for sure, object everywhere :)
I'll spend some time thinking about refactoring away from generics
Berin Loritsch
@bloritsch
Jul 07 2016 22:30
I personally would allow for wider input and use validators to flag it as bad or needing correction. I've worked with some software that was so restrictive it was maddening.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:30
it is solid advice
I can tweak the units lib if needed
Berin Loritsch
@bloritsch
Jul 07 2016 22:31
Feel free to keep generics in the model classes, but the controls seem to work better with doubles for numbers and reasonable base objects.
I have to go soon (busy busy), any parting questions?
Johan Larsson
@JohanLarsson
Jul 07 2016 22:33
thanks for your time, much appreciated!
Berin Loritsch
@bloritsch
Jul 07 2016 22:33
no problem
Johan Larsson
@JohanLarsson
Jul 07 2016 22:33
these are the unit types btw
awesome to be able to bind directly to them
and not have converters or extract the double in the viewmodel
Berin Loritsch
@bloritsch
Jul 07 2016 22:33
I don't see why that shouldn't still be the case.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:33
whole classes of bugs goes away
maybe you are right and there is a nicer solution
Berin Loritsch
@bloritsch
Jul 07 2016 22:35
this is my current baby. So I get where you are coming from.
see you later.
Johan Larsson
@JohanLarsson
Jul 07 2016 22:36
I'm not gonna hold you here, have an awesome one and thanks for your time
yeah, bai