These are chat archives for AvaloniaUI/Avalonia

4th
Jan 2015
Steven Kirk
@grokys
Jan 04 2015 14:03
hmm not sure about resources
i never really liked the syntax at least
it's very verbose
i would really like to be able to put expressions directly in xaml
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:43
whoops
I couldn't imagine how to do that!
into a binding?
totally mind blowing!
the thing is that a view shoud never be allowed to contain business logic
it's for that why we have things like ViewModels!
I mean, XAML isn't necessarily a UI thing
it could be used to define rules
but at the moment I'm using XAML to define the UI
in the UI side, there shouldn't be any business logic attached to it
I don't know if that's what you mean by "put expressions directly in xaml"
and now that I realize, I don't know if you were talking about validation!
haha
Steven Kirk
@grokys
Jan 04 2015 14:47
well if a view shouldn't contain business logic, what are value converters for?
sometimes it's needed
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:47
sorry, I'm about to leave to Madrid again and I hadn't have time to read much!
Steven Kirk
@grokys
Jan 04 2015 14:48
as for how to implement it... not entirely sure!
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:48
value converters are there just to transfer purely UI related values to "refined" view model values
Steven Kirk
@grokys
Jan 04 2015 14:48
yes, in a very inconvenient manner!!!
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:49
in fact, the aren't even a XAML thing
a binding is provided with a valueconverter
in order to be able to translate from one endpoint to another
Steven Kirk
@grokys
Jan 04 2015 14:50
give an example of something you think is a valid use for a value converter
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:50
for instance, converting a true false to a visibility
Steven Kirk
@grokys
Jan 04 2015 14:50
ok yep that's the classic
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:50
a true false has sense in a ViewModel
Steven Kirk
@grokys
Jan 04 2015 14:51
(although perspex doesn't have Visibility)
(it just has IsVisible)
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:51
haha
for instance
converting a Uri
to a Bitmap
the viewmodel could know about uris
or even tokens to bitmaps
the converter knows what to translate those tokens
it's just a matter of using SRP properly
Steven Kirk
@grokys
Jan 04 2015 14:52
here's what you have to type to use a valueconverter in WPF:
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:52
the View should be as more agnostic as it could
Steven Kirk
@grokys
Jan 04 2015 14:52
<Window.Resources>
    <BooleanToVisibilityConverter x:Key="b2v"/>
</Window.Resources>

<Control Visibility="{Binding Visibility, Converter={StaticResource b2v}}"
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:53
yes
Steven Kirk
@grokys
Jan 04 2015 14:53
it's too much!
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:53
I agree
Steven Kirk
@grokys
Jan 04 2015 14:53
and that's without writing the actual value converter!
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:53
there might be a better way
Steven Kirk
@grokys
Jan 04 2015 14:54
IMO you should be able to write
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:54
I haven't planned anything about them to date
Steven Kirk
@grokys
Jan 04 2015 14:54
<Control Visibility="{Binding Visibility ? Visible : Hidden}"/>
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:54
uhmmm
pretty legible
Steven Kirk
@grokys
Jan 04 2015 14:55
it's crazy when the markup takes 20x more lines than doing it in plain C#
(20x including the value converter)
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:55
haha
let me think about it
Steven Kirk
@grokys
Jan 04 2015 14:55
i realise it might be difficult!
but that's no reason to settle for an inconvenient solution IMO
we should be trying to put things forward rather than recreating the status quo...
i can dream at least ;)
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:56
the solution you propose includes compilable code
I mean, you are even using an operator
Steven Kirk
@grokys
Jan 04 2015 14:56
yeah. i think roslyn would be perfect for that
i believe it has a REPL
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:57
so you think that the binding could just convert values using the code inside
Steven Kirk
@grokys
Jan 04 2015 14:57
so it should be capable of doing it
yeah, that's what would be ideal to me
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:57
but, don't you think that it could be dangerous to include code inside the view itself?
I don't know
!!
Steven Kirk
@grokys
Jan 04 2015 14:58
it could be misued
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:58
I don't know anything about Roslyn
Steven Kirk
@grokys
Jan 04 2015 14:58
but everything can be misued
i don't know much! ;)
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:58
I hope @glennblock could give us his opinion about that
Steven Kirk
@grokys
Jan 04 2015 14:58
yeah, i'd be interested to hear other opinions
José Manuel Nieto
@SuperJMN
Jan 04 2015 14:58
I don't have the knowledge to give a founded opinion!
Steven Kirk
@grokys
Jan 04 2015 14:59
i do quite a lot of work using knockoutjs and being able to use simple expressions in there is priceless
i always hate the feeling when working with WPF
"oh god, i've got to write a converter now"
"all i want to do is negate a value!"
tbh i think valueconverters are the worst of both worlds
if you subscribe to the idea that there should be zero logic in views then you should expose the value to be exposed to the markup in your viewmodel
but if you want to be able to put logic in views, valueconverters make it really long-winded
but like i say, i'd be interested in hearing other opinions
José Manuel Nieto
@SuperJMN
Jan 04 2015 20:06
I agree with that
writing valueconverters is nasty
the problem with the expressions you say is that need to be compiled
to a Func<object, object> maybe
(in the simplest case)
I think of a problem: what if the user doesn't want to use just a little ? operator, but a complex conditional logic, like n case switch?
the conversion expresion should point to a method
but, which method?
<Button IsVisible="{Binding X, Converter=SomeMethod}" />
José Manuel Nieto
@SuperJMN
Jan 04 2015 20:11
I wonder about the location and scope of that
Glenn Block
@glennblock
Jan 04 2015 21:41
weighing in late
What is the Roslyn-releated question?
using if for binding expressions?
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:18
the next feature that I want to implement will be really funny... !
Glenn Block
@glennblock
Jan 04 2015 22:18
@SuperJMN what was the Roslyn question?
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:19
bindings work ONLY for level 0 property paths. Just the plain simple name of the property. No real property paths!
Hi Glenn!
Glenn Block
@glennblock
Jan 04 2015 22:19
Hola
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:20
Haha, looks like you Spanish Engine is just warming up!
the thing is that Steven (@grokys) thinks of a new cool way tod implement in-place type conversion in bindings
so you can put code directly
Glenn Block
@glennblock
Jan 04 2015 22:21
where?
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:21
into the binding
like this:
<Control Visibility="{Binding Visibility ? Visible : Hidden}"/>
Glenn Block
@glennblock
Jan 04 2015 22:22
I see….personally I dislike doing this
though Knockout JS supports this kind of syntax
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:22
he says, and I agree, that the whole ValueConverter thing is very bulk and verbose
Glenn Block
@glennblock
Jan 04 2015 22:22
I agree with that as well
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:22
I also think, like you, that putting code into the view could be a very bad idea
Glenn Block
@glennblock
Jan 04 2015 22:22
but if you use a view model you could just bind to a model property
yes
though people still do it
its generally hard to test
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:23
yes
Glenn Block
@glennblock
Jan 04 2015 22:23
and easy to break the UI itself if you have a typo
I prefer the model of having a VM with properties
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:23
I personally would like to support MVVM and be focused on it
Glenn Block
@glennblock
Jan 04 2015 22:23
observable properties
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:23
yes, that's the way it works right now
Glenn Block
@glennblock
Jan 04 2015 22:23
binding expressions then are just property paths
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:23
but the problem with that
with the bindings, I mean
Glenn Block
@glennblock
Jan 04 2015 22:24
I think I heard you say…it’s only top level
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:24
and with values and VMs being transferred
yes, yes
but forget that for a moment
about the value conversion
I think that ValueConverters should have their place
but I don't know it the current WPF implementation could be improved in some way
99% of the time, ValueConverters are specified via resource location
using a StaticResource markup extension
and that involves some kind of resource facility
like ResourceDictionaries
I mean:that is hard work
and has some impact into the base PerspexObject definition
so, if the way to implement value converters is doing it via resource location and ValueConverters => it implies the whole Resource systems has to be implemented as well
if someone can imagine a better way to do value conversions in a Binding, like using build-it code, that part about resources can be postponed
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:29
(I think Resources will be necessary at some point)
Glenn Block
@glennblock
Jan 04 2015 22:29
so the main issue here is that doing binding to properties requires converters?
and who to remove that need?
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:29
yes
that's it!
Glenn Block
@glennblock
Jan 04 2015 22:30
give me an example
I know what coverters are….but just to give me specific context
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:30
well, an example that I've used in the real life
the ViewModel contains a Uri
that is abstract enough
and in the view, that Uri will be the source for an Image
I think it works just right without any value conversion, because there is a TypeConverter that makes the conversion for you
but if it doesn't, you definitely need to "polish" the edges in each endpoint of the binding
Glenn Block
@glennblock
Jan 04 2015 22:32
well that could also be handled by having a Uri property on the VM
and a readonly image property
basically that is a simple way to address conversions
have properties that match on type for binding one way
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:33
OK
another case!
Glenn Block
@glennblock
Jan 04 2015 22:33
and a read only property of the final type for the other way
if you use something like INPC it can still work nicely
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:33
ViewModel has Color
and the View works with Brushes
Glenn Block
@glennblock
Jan 04 2015 22:33
as you raise a notification whenever the setter prop changes
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:34
Color is not related to the UI
Glenn Block
@glennblock
Jan 04 2015 22:34
expose a prop on the VM of type brush
when the color changes, update the brush prop
thats easy enough
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:34
yes, but Brushes are absolutely platform dependent
Glenn Block
@glennblock
Jan 04 2015 22:34
so
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:34
Color is maybe a class defined into a PCL
Glenn Block
@glennblock
Jan 04 2015 22:34
VMs are closer to the UI
hmm
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:35
closer, but in terms of business
Glenn Block
@glennblock
Jan 04 2015 22:35
I guess the question is what problem are you trying to solve
yeah but VMs can absolutely have platform dependencies
UI dependencies
a VM can expose controls
it’s job is to service the view
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:36
I'm absolutely against VMs containing UI controls
Glenn Block
@glennblock
Jan 04 2015 22:36
however you are correct that if the VM has platform-specific dependencies and is used cross plat, that is an issue
you may be
but there’s nothing fundamentally problematic of dong it
the main thing about the VM is it should contain the UI logic which should not live in the view
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:36
ideally, and it's not very difficult to achieve, VMs are abstract enough to work with the bare minimum dependencies, and the dependencies are almost 99% business specific
yes, that's right!
Glenn Block
@glennblock
Jan 04 2015 22:37
I agree it is ideal to keep an abstraction, but not required to have zero UI dependencies
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:37
the thing is, do you believe that value conversion is needed or not?
Glenn Block
@glennblock
Jan 04 2015 22:37
you can depend on APIs which are specific like exposing dependency objects, colors, bruishes
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:38
yes, I agree
Glenn Block
@glennblock
Jan 04 2015 22:38
I can see value in having the ability to plug them in
but I am saying you can solve many problems without them
and still be clean
and using the brush example….if I drop xPlat as a requirement
I don’t see any huge issue with exposing a brush on the VM
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:39
haha
Glenn Block
@glennblock
Jan 04 2015 22:39
that is set based on a change to a Color property
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:39
OK
Glenn Block
@glennblock
Jan 04 2015 22:39
but it all depends….I am not promoting hanging controls off of a VM
but I am saying I don’t think there is anything fundamental that prevents it
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:39
haha, it's good to hear!
for sure there will be cases when you would like to convert a value
Glenn Block
@glennblock
Jan 04 2015 22:40
yes but my point is you can often do that using a VM property
without needing special converters
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:40
I can think of the infamouse InverseBooleanConverter
Glenn Block
@glennblock
Jan 04 2015 22:40
though if something is common enough, sure a converter is nice
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:41
yes, the cost is having to add more properties to the VM
OK, given that converters are useful to keep VMs clean and simple:
how do you think they could be implemented?
the embedded code is dangerous
Glenn Block
@glennblock
Jan 04 2015 22:42
how about simple lambdas in code?
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:42
the other solution, using static resources
Glenn Block
@glennblock
Jan 04 2015 22:42
a collection of converters…each converter is a func
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:42
uhmm
Glenn Block
@glennblock
Jan 04 2015 22:42
I can register them simply in code
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:43
mind blowing!
and you reference them implicitly or explicitly?
Glenn Block
@glennblock
Jan 04 2015 22:43
you could also have a converter interface
the method to register could be overloaded
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:43
"{Binding Blah, Converter=SomeDefinedConverter}"
Glenn Block
@glennblock
Jan 04 2015 22:43
you mean in XAML?
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:44
yes
Glenn Block
@glennblock
Jan 04 2015 22:44
are we talking about in XAML?
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:44
yes, I am
:)
Glenn Block
@glennblock
Jan 04 2015 22:44
sure that works
I register named converters
either I give an IValueConverter or a lamdba
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:44
withouth any kind of scope, at least for now
what do you think?
Glenn Block
@glennblock
Jan 04 2015 22:45
then you give it a key
if you add IoC support
this is the kind of thing that could be just registered in the IOC
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:45
keys should be registered
each converter would be in the container
localizable with its key
Glenn Block
@glennblock
Jan 04 2015 22:45
I see
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:45
It looks like a cool way to me
Glenn Block
@glennblock
Jan 04 2015 22:45
so the question if it is in the container is how to get the loose funcs into the container
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:46
easy to implement and handy
Glenn Block
@glennblock
Jan 04 2015 22:46
you could just say it is registered as a kehy
most containers support keyed
like autofac has named
so if i specify a name in the binding
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:46
yes, the one I use ATM does support them
Glenn Block
@glennblock
Jan 04 2015 22:46
it goes to the container and says give me the named instance
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:46
cool!
Glenn Block
@glennblock
Jan 04 2015 22:46
what are you using?
I’d recommend autofac
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:46
Grace
Glenn Block
@glennblock
Jan 04 2015 22:46
lightweight, really good
link?
never heard of it
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:47
it doesn't really matter
Grace is really cool
Glenn Block
@glennblock
Jan 04 2015 22:47
send me a link
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:47
it's developed by a friend
Glenn Block
@glennblock
Jan 04 2015 22:47
autofac has huge adoption
Glenn Block
@glennblock
Jan 04 2015 22:47
and a rich module config story
and performs really well
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:48
well, the cool way about containers is that they are almost all the same in functionality
Glenn Block
@glennblock
Jan 04 2015 22:48
well…kinda
they all have different things that make them sepcial
autofac has a really nice terse fluent api
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:48
haha, yes! but an IoC container should be use just to compose an resolve in the composition root
so if you handle that situation with A or B, you're done!
the switch is easy
Glenn Block
@glennblock
Jan 04 2015 22:49
well that is orgthagonal to configurability
sure
yes if you put it correctly into your apl
app
you can swap it
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:49
Ian Johnson is the head behind StyleMVVM
friends with Sacha Barber
Glenn Block
@glennblock
Jan 04 2015 22:50
does it support hierarchical containers?
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:50
I don't know
I've got pretty basic usage skills about IoC containers
:(
Glenn Block
@glennblock
Jan 04 2015 22:50
looking at the description, seems like it has cherry picked from various containers
like Autofac
in terms of ideas / features
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:50
just the basic
Glenn Block
@glennblock
Jan 04 2015 22:51
looks like it supports hierarchy
custom lifestyles
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:51
what I see from it is that is very straightforward to use it and provides you with a lot of configurability
it's great for what I see
Glenn Block
@glennblock
Jan 04 2015 22:51
I am not saying it doesn't
I am not against a new one
the question I always ask is what is different, why a new one
just want to know what it brings that is different
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:51
hahaha
Glenn Block
@glennblock
Jan 04 2015 22:52
he says it is faster than all the other IoCss
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:52
I don't have any problem changing it!
it's the value conversion what worries me at the moment :smile:
Glenn Block
@glennblock
Jan 04 2015 22:52
true
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:52
I like your idea
I think I will implement it
Glenn Block
@glennblock
Jan 04 2015 22:52
we arrived at this discussion based on keys
:-)
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:52
haha
it's cool how we I finally follow up a conversation
you know speaking is not my strenght!
about the property paths
Glenn Block
@glennblock
Jan 04 2015 22:54
Grace supports names looks like
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:54
it's the topic I was talking about to the general public here
Glenn Block
@glennblock
Jan 04 2015 22:54
just looking at the code and found this
so there must be a way to use string names
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:54
yes, there it is!
I tend to use Grace because if I have any doubt, Ian kindly helps me :)
though my questions are very easy, :blush:
this is the interface the container implements
so Locate does accept an export name
so just need to see how to register the name
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:56
the property paths => currently, my binding support is very very limited. It only works when you specify a level0 Path
so it has child containers
this is good
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:56
viewModel.Date: OK! viewModel.Date.Minute: FAILS MISERABLY
it does support?
Glenn Block
@glennblock
Jan 04 2015 22:57
it supports child containers
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:57
wow, I will have to congratulate Ian
he's doing a great job
Glenn Block
@glennblock
Jan 04 2015 22:57
looking at it..he appears to have looked at many diff containers
and pulled the things he likes in
and then focused on perf
so far looks pretty good…though haven’t used it
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:58
any feature you like, you can tell him and we will probably implement it in a few days
it's nice to hear!
Glenn Block
@glennblock
Jan 04 2015 22:59
just initial impressions
:-)
José Manuel Nieto
@SuperJMN
Jan 04 2015 22:59
OK
about the property paths
It's my next challenge
I have to think a lot about it
:worried:
I will come soon with my findings!
I've leaving now, going to bed
thanks for the ideas, Glenn!
Glenn Block
@glennblock
Jan 04 2015 23:01
before you go
the property paths
what are you trying to handle there?
binding to customer.name ?
btw..here’s how you export by name
José Manuel Nieto
@SuperJMN
Jan 04 2015 23:05
yes, yes
It's a bit dirty, I know
Glenn Block
@glennblock
Jan 04 2015 23:05
container.Configure(c => c.Export(“FooConverter”, …))
José Manuel Nieto
@SuperJMN
Jan 04 2015 23:06
yes, this is the way the container gets configured
Glenn Block
@glennblock
Jan 04 2015 23:06
yeah but this is how you set a name
José Manuel Nieto
@SuperJMN
Jan 04 2015 23:06
haha, yes! it is
Glenn Block
@glennblock
Jan 04 2015 23:06
Export is overloaded
José Manuel Nieto
@SuperJMN
Jan 04 2015 23:07
It seems you like Grace :smile:
I have used it and I really like it.
Glenn Block
@glennblock
Jan 04 2015 23:08
actually syntax is a little different
José Manuel Nieto
@SuperJMN
Jan 04 2015 23:08
by the way, if you or anyone would like to help me with property paths in bindings, I will greatly appreciate it
Glenn Block
@glennblock
Jan 04 2015 23:08
but it appears named exports / resolving are supported which is the key thing
José Manuel Nieto
@SuperJMN
Jan 04 2015 23:08
see you tomorrow!
Glenn Block
@glennblock
Jan 04 2015 23:09
bye
José Manuel Nieto
@SuperJMN
Jan 04 2015 23:09
yes, it's supported. If it wasn't, Ian will implement it, for sure! haha
He tries hard to make Grace one of the best IoC Containers out there!
Glenn Block
@glennblock
Jan 04 2015 23:10
I would say that is the goal of most IoC authors ;-)
aside from perf, I am still not seeing why I would use this over Autofac
but that doesn’t make it bad
for comparison, Autofac has close to 1 million downloads
anyway, it is all good
Like I said from what I see…looks nice