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

8th
Jul 2016
Johan Larsson
@JohanLarsson
Jul 08 2016 10:24
@bloritsch solved it without hax, there was a refactoring opportunity for a nongeneric baseclass.
Johan Larsson
@JohanLarsson
Jul 08 2016 10:33
Animation.gif
question is if ^ should be the default style
or a plain style with just [label : value] stacked.
Berin Loritsch
@bloritsch
Jul 08 2016 10:48
Your lookless control will need some style. That looks like you have some functionality you want to always be present (validation hooks, info area, units, etc).
Johan Larsson
@JohanLarsson
Jul 08 2016 10:49
yeah, question is what is a sensible default
probably not very important as the default style will not be right for any app
Berin Loritsch
@bloritsch
Jul 08 2016 10:49
Only thing I would suggest is to make sure you use your TemplateBinding for normal style bits like Foreground/Background etc.
Johan Larsson
@JohanLarsson
Jul 08 2016 10:50
blob
Berin Loritsch
@bloritsch
Jul 08 2016 10:50
If you handle the template binding on most of that stuff, then it should even look at home in a Mahapps app
Johan Larsson
@JohanLarsson
Jul 08 2016 10:50
@bloritsch yeah, the row control has styles for {header, value, suffix, error, info}
then in the template the controls are template bound tow the styles
it should be very flexible
Berin Loritsch
@bloritsch
Jul 08 2016 10:52
That's good. The less people feel like they have to dip into style territory the better.
As to the colors for error, etc. You may want to expose those as DependencyProperties on your control and keep the defaults as they are.
Johan Larsson
@JohanLarsson
Jul 08 2016 10:53
<propertyGrid:Rows DataContext="{Binding EditableCopy}"
                    ValueWidth="60">
    <TextBlock Style="{StaticResource HeaderTextBlockStyle}" Text="Units" />
    <unitRows:LengthRow Header="Length1" Value="{Binding Length1}" />
    <unitRows:LengthRow Header="Length2" Value="{Binding Length2}" />
    <unitRows:LengthRow Header="Length2" Value="{Binding Length2}" />
</propertyGrid:Rows>
Berin Loritsch
@bloritsch
Jul 08 2016 10:53
That also gives the flexibility to users to use a slightly different red/green/blue that works better with their app.
Johan Larsson
@JohanLarsson
Jul 08 2016 10:54
@bloritsch that would mean redundancy
^^ pretty sweet xaml imo
Berin Loritsch
@bloritsch
Jul 08 2016 10:55
Hmm.. Then maybe go with the MahApps strategy of giving them a name and dynamically binding to the resource name...
Johan Larsson
@JohanLarsson
Jul 08 2016 10:55
I'll write a sample styling the old value so you can flame it
Berin Loritsch
@bloritsch
Jul 08 2016 10:55
And the xaml is nice and compact. That's what I like to see
Johan Larsson
@JohanLarsson
Jul 08 2016 10:55
yeah, no noise
not having converters for min, max & value and suffix as text
meaning all can be wrong
Berin Loritsch
@bloritsch
Jul 08 2016 10:56
Yes, but correctable.
Johan Larsson
@JohanLarsson
Jul 08 2016 10:56
how do you mean?
Berin Loritsch
@bloritsch
Jul 08 2016 10:58
Your demonstration allowed the user to type invalid information, and gave meaningful feedback of how to fix it.
Johan Larsson
@JohanLarsson
Jul 08 2016 10:58
oh, yeah
I meant as a developer, binding min, max & value with converter + suffix as text means many ways to fail
say you change only three to inches
Berin Loritsch
@bloritsch
Jul 08 2016 11:01
Hmm. I wonder if using TypeConverters might make sense for this case. You can see an example with my newly implemented HotSpot type in Discarta reference typeconverter and the typeconverter itself
Johan Larsson
@JohanLarsson
Jul 08 2016 11:02
the units have typeconverters
both good and bad
but these controls don't use them
Berin Loritsch
@bloritsch
Jul 08 2016 11:02
OK. What is the type for Min/Max?
Johan Larsson
@JohanLarsson
Jul 08 2016 11:03
Length
the control exposes {ScalarMinValue, ScalarMaxValue, ScalarValue} for templatebinding
Berin Loritsch
@bloritsch
Jul 08 2016 11:03
OK, so it's not something like string. I got that impression from the previous message
Johan Larsson
@JohanLarsson
Jul 08 2016 11:04
those are converted and kept in sync if Unitchanges
Berin Loritsch
@bloritsch
Jul 08 2016 11:04
Clever. I know some apps that could use stuff like that.
Way better than just slapping a new label on the same value.
Johan Larsson
@JohanLarsson
Jul 08 2016 11:04
yeah, same here
the reason for the lib was that I was sick of writing it over and over
and bugs
it is free open source so just use the nuget or clone and modify
a couple of days before releasing it though
Berin Loritsch
@bloritsch
Jul 08 2016 11:06
Well, I'm in the throws of finishing up an app for release in the next month and a half with half the crew as when we started.
It'll be a bit before I can surface enough to really play with it deeply
Speaking of, I'm off to work. ttyl
Johan Larsson
@JohanLarsson
Jul 08 2016 11:10
<Window.Resources>
    <Style TargetType="{x:Type propertyGrid:UnitRowGeneric}">
        <Setter Property="OldValueStyle">
            <Setter.Value>
                <Style BasedOn="{StaticResource DefaultUnitOldValueStyle}" TargetType="{x:Type TextBlock}">
                    <Setter Property="Foreground" Value="Green" />
                </Style>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type propertyGrid:LengthRow}" BasedOn="{StaticResource {x:Type propertyGrid:UnitRowGeneric}}"/>
</Window.Resources>
<propertyGrid:Rows DataContext="{Binding EditableCopy}" OldDataContext="{Binding DataContext.LastSaved, RelativeSource={RelativeSource AncestorType={x:Type Window}}}">
    <propertyGrid:LengthRow Header="default" Value="{Binding LengthValue}" />
    <propertyGrid:LengthRow Header="explicit cm"
                                Unit="cm"
                                Value="{Binding LengthValue}" />
</propertyGrid:Rows>
that is what styling the old value would look like
a bit verbose
but upside is that it works even if you use different controls in the template
say you want to use a textbox for the old value to enable copy pasting, then pass in a style for textbox
Johan Larsson
@JohanLarsson
Jul 08 2016 11:35
perhaps overly flexible, it is a balance
Johan Larsson
@JohanLarsson
Jul 08 2016 13:53
I try to avoid hacks using OnApplyTemplate etc. it makes the code hard to reason about.
Especially for libs.
Johan Larsson
@JohanLarsson
Jul 08 2016 20:44
still a massive duplication but now it is in code and can be generated np
the duplication moved
things are nice and typed now and no hax