These are chat archives for AvaloniaUI/Avalonia

23rd
Feb 2015
José Manuel Nieto
@SuperJMN
Feb 23 2015 10:00
Somebody to create a XamlReader?
:D
the official one is not portable
if somebody is brave enough, just do it!
Steven Kirk
@grokys
Feb 23 2015 17:08
hi @SuperJMN - I've changed Perspex to not define it's own ICommand
regarding the listbox error, i can't run your ShowCase app as obviously i don't have your modified System.XAml
i tried to reproduce in the test app but i couldn't get it to crash
any chance you could make a small repro without the xaml stuff?
José Manuel Nieto
@SuperJMN
Feb 23 2015 17:25
Hi @grokys! I've come to the conclusion that it may be a problem in my side
I think I broke some internal thing :S
in my branch
I have 2 branches: it works in one, and not in the other. So I have to discover what I broke!
so, don't worry
I will tell you if I think there's a problem with your code
José Manuel Nieto
@SuperJMN
Feb 23 2015 21:30
OK, I think I'm blocked
the problem is that I'm completely lost with Schedulers and Dispatchers
it's too low level for my simple mind
I don't understand why the ShowCase application is failing
I have a list with items (viewmodels)
whenever you type a search query, I use Rx to "throttle" the keystrokes, so it waits half a second after the last key before the actual service is called (the Bing Search)
José Manuel Nieto
@SuperJMN
Feb 23 2015 21:36
after the results are retrieved, I get them and I generate a ResultsViewModel for each SearchResult
and this is where it reaches the part that I don't understand:
in the Perspex application, each search query retrieves retrieve the results twice!
José Manuel Nieto
@SuperJMN
Feb 23 2015 21:50
whoops, I think I get it!
  IEnumerable<Control> IItemContainerGenerator.Generate(IEnumerable items)
    {
        List<Control> result = new List<Control>();

        this.State = ItemContainerGeneratorState.Generating;

        try
        {
            foreach (object item in items)
            {
                Control container = this.CreateContainerOverride(item);
                container.TemplatedParent = null;
                this.AddInternal(item, container);
                result.Add(container);
            }
        }
        finally
        {
            this.State = ItemContainerGeneratorState.Generated;
        }

        return result;
    }
this iterates across all the items
and since my items are retrieved from a select (LINQ) each time the items are iterated, new instances of each ViewModel is created
so the items are always different instances
and in the second search query, when the results should be refreshed, the old items are tried to be removed using a dictionary
as the items are removed looking for the same instance, they are not found, because none of the instances are the same that was originally created
José Manuel Nieto
@SuperJMN
Feb 23 2015 21:58
haha, solved!
OK, this was really hard ... it doesn't have to do with threading, dispatchers or schedulers, but with the way the items are refreshed after a ItemsChanged method is called after the Items property changse
when the ItemsChanged method is called, this line is executed
(at ItemsPresenter/ItemsChanged)
 this.Panel.Children.RemoveAll(generator.Remove(value.Item1));
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:04
and this one follows in execution:
    IEnumerable<Control> IItemContainerGenerator.Remove(IEnumerable items)
    {
        List<Control> result = new List<Control>();

        foreach (var item in items)
        {
            result.Add(this.RemoveByItemInternal(item));
        }

        return result;
    }
in my case, items was a LINQ query (not a materialized list)
concretely, it was a searchResult.Select(sr => new SearchResultViewModel(sr) )
Steven Kirk
@grokys
Feb 23 2015 22:06
ahhh ok
i guess it probably shouldn't iterate over the collection when the Items change
as it can just delete everything
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:07
do you undertand?? yes, I explaint myself like a close book
Steven Kirk
@grokys
Feb 23 2015 22:07
i think so yes
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:07
yes, I think it can do the same!
the idea was great
but a completely different set of items were tried to be removed!
Steven Kirk
@grokys
Feb 23 2015 22:08
adding a lazily-enumerated collection to a list box would be kinda unusual
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:08
it could have worked if I implemented Equals
Steven Kirk
@grokys
Feb 23 2015 22:08
but i agree it should handle it
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:08
yes, that's it
when the items are generated, materialize them
so, if you want to remove them afterwards, you can look for the original instances
Steven Kirk
@grokys
Feb 23 2015 22:09
sorry, i don't understand that last part
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:09
uhmm, maybe I'm wrong
but
when you create the dictionary that relates item with container
those items should be saved to a like as a "backup"
Steven Kirk
@grokys
Feb 23 2015 22:11
if you change ItemsPresenter.cs:100 to this.Panel.Children.Clear(); does it fix the problem?
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:11
should you want to remove them
let me see :)
absolutely!
as expected :D
Steven Kirk
@grokys
Feb 23 2015 22:13
ok, i will commit that change
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:13
but what I wanted to tell you is
do you feel that it's necessary to backup the items?
Steven Kirk
@grokys
Feb 23 2015 22:13
backup the items?
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:13
yes
here you iterated with a foreach
over all of them
is there any other case when you would like to iterate through the items?
(iterating across could be dangerous of the enumerable is, say, a select, like in my case!)
to prevent future problems, if you really need the items, you could invoke a "ToList" at the beginning
that is what I was referring to :)
Steven Kirk
@grokys
Feb 23 2015 22:15
yeah, possibly... um, not sure
what does WPF do?
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:15
OK!
Steven Kirk
@grokys
Feb 23 2015 22:16
assigning a lazily-evaluated collection to a list box is a bit of a weird thing to do
not sure i've ever done it
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:16
in WPF it works
I did lots of times :)
it seems that it materializes the items
Steven Kirk
@grokys
Feb 23 2015 22:17
ok, then if WPF handles it it should probably work like that
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:17
it was about driving me crazy
believe me, I was working all the day in this issue
Steven Kirk
@grokys
Feb 23 2015 22:17
how do we tell apart a lazily-evaluated collection from a normal collection?
ICollection?
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:18
or IList
I think the best way to do it is to invoke a ToList over the items when Items is changed
Steven Kirk
@grokys
Feb 23 2015 22:18
IList implements ICollection
no, that would break observable collections
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:19
oh boy
yes, you're right
OK, let's see try not to iterate over Items
hmm checking for ICollection won't work
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:22
the problem would not happen if each item implement Equals
but that shouldn't be needed
Steven Kirk
@grokys
Feb 23 2015 22:22
yeah, but that's not something that can be enforced
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:22
yes, you see
Steven Kirk
@grokys
Feb 23 2015 22:23
i think as you say the best way to do it would be to ToList() the items if the user passes a lazily-evaluated collection
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:23
OK, for now it's fine that this scenario is at least taken into account!
Steven Kirk
@grokys
Feb 23 2015 22:23
however i'm not sure how to detect that case...
can't find anything from a quick bit of googling
maybe the best thing for now would be to add an issue
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:24
OK,
but are you going to put the Clear() ?
Steven Kirk
@grokys
Feb 23 2015 22:24
yeah, i'll put that in for now
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:24
it fixes the problem for now, I think
Steven Kirk
@grokys
Feb 23 2015 22:24
as it at least fixes the major problem
yes
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:25
OK, then the ShowCase works
Now I'm going to answer to Harikrishna Menon
he took the time to answer to my Twitter questions
it's very very strange
Steven Kirk
@grokys
Feb 23 2015 22:26
oh i've not seem them
will take a look now
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:27
since I wanted to ask him about 2 years ago and almost ignored me
that is, otherwise, very normal!
why would have taken me into consideration? I'm a silly coding squirrel
:D
Steven Kirk
@grokys
Feb 23 2015 22:28
is this the tweet of Feb 12th?
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:28
but yes, he answered nicely
no, no, today
Untitled.png
Steven Kirk
@grokys
Feb 23 2015 22:30
oh wow!!!
excellent news!
what do you think of this for an alternative markup? http://pastebin.com/30vYFt7e
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:35
It looks super nice!
I won't mind using it :)
Steven Kirk
@grokys
Feb 23 2015 22:36
thing is, i'm not sure i should be working on markup now...
there are so many more basic things i need to get done!
Richard Simpson
@RichiCoder1
Feb 23 2015 22:37
Reminds me of QML
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:37
yes, haha
I'm able to deal with XAML
Steven Kirk
@grokys
Feb 23 2015 22:38
yeah exactly...
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:38
but in any ways I am to presentation!
but it could be good
Steven Kirk
@grokys
Feb 23 2015 22:38
@RichiCoder1 yes it is very much inspired by QML!
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:38
if I am able to collaborate in the core a bit more
Steven Kirk
@grokys
Feb 23 2015 22:38
the idea is to use Roslyn to parse the property values
so that you can put any expression in there
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:39
for example, making TextAlignments work
Steven Kirk
@grokys
Feb 23 2015 22:39
yeah, if you would like to work on the core you'd be welcome!
things like dialog, menus etc all still need to be done
i think i can do dialogs reasonably easily
for menus i think all of the primitives should be in place
the alternative markup syntax was taken from @xamldude 's work
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:56
:) how cool!
well, I hope to attract the attention of Hari and Rob
they're one of the most brilliant minds in the WPF world
it's never bad that people could see the snapshots and say to others "hey, there are some guys that want to make a cross-platform WPF"
"apart from Xamarin.Forms?"
"yes, apart from that"
"open source?"
"oh, they're crazy! WPF is a work of years!"
Steven Kirk
@grokys
Feb 23 2015 22:59
haha yeah, years of work for many people!
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:59
MANY
Steven Kirk
@grokys
Feb 23 2015 22:59
i've not done too bad then :)
José Manuel Nieto
@SuperJMN
Feb 23 2015 22:59
no, absolutely awesome
Steven Kirk
@grokys
Feb 23 2015 22:59
but help on the core is always appreciated!
as long as we don't have to argue about coding style ;)
José Manuel Nieto
@SuperJMN
Feb 23 2015 23:00
the dispatching, threading and pickles in vinegar is completely out of my reach
I'm a dumb there
an absolute dumb!
I have to go to the core and learn
hahaha, you're right to the point
your code is in general terms, so creamy
Steven Kirk
@grokys
Feb 23 2015 23:01
I'd advise: try looking at the WPF Menu's template and try to port that to Perspex
José Manuel Nieto
@SuperJMN
Feb 23 2015 23:01
hahaa
Steven Kirk
@grokys
Feb 23 2015 23:02
but leave out all the hard stuff ;)
José Manuel Nieto
@SuperJMN
Feb 23 2015 23:02
first I should try to get how Perspex does the styling thing!
it's a mystery for me, yet
Steven Kirk
@grokys
Feb 23 2015 23:02
i think it's pretty simple, conceptually at least
Perspex.Themes.Default defines all of the controls' themes
José Manuel Nieto
@SuperJMN
Feb 23 2015 23:03
by the way, the code base could be greatly improved using Ambient Contexts, as Mark Seemann suggest in "Dependency Injection in .NET"
Steven Kirk
@grokys
Feb 23 2015 23:03
ok i don't know what that is
José Manuel Nieto
@SuperJMN
Feb 23 2015 23:03
I was a heavy Service Location user a few years ago
and I discovered the perils of it
Steven Kirk
@grokys
Feb 23 2015 23:04
do you have a link?
José Manuel Nieto
@SuperJMN
Feb 23 2015 23:04
yes
it's a public post
in fact, I removed EVERY Service Location call in my ShowCase branch
now, they are Contexts
they thing is that, each time you use a locator, your hiding a dependency
and the network of dependencies could grow exponentially
Steven Kirk
@grokys
Feb 23 2015 23:06
yeah the service locator stuff was a temporary measure
i just needed to get something in place so i could unit test
José Manuel Nieto
@SuperJMN
Feb 23 2015 23:07
but also, lose track of what need what
I solved it in my branch
look at the initialization
it's far from being perfect, yet...
Steven Kirk
@grokys
Feb 23 2015 23:07
is it all in a separate branch?
José Manuel Nieto
@SuperJMN
Feb 23 2015 23:07
but everything is composed at the very beginning
I separated it, yes
        PlatformCoreContext.Current = new WindowsPlatformCoreContext();
        PlatformInputContext.Current = new WindowsInputContext(new FocusManager());
        RenderingPlatform.Current = new Direct2D1RenderingPlatform();

        var keyboardDevice = (WindowsKeyboardDevice)PlatformInputContext.Current.Keyboard;
        var mouseDevice = (WindowsMouseDevice)PlatformInputContext.Current.Mouse;
        PresentationContext.Current = new DefaultPresentationContext(keyboardDevice, mouseDevice);
Steven Kirk
@grokys
Feb 23 2015 23:09
ok, let me read the article
José Manuel Nieto
@SuperJMN
Feb 23 2015 23:09
I'm not satiesfied with the look, yet
but it's a step
OK! I'm going to bed
have a good night
This message was deleted
thanks for the nice time here!
Steven Kirk
@grokys
Feb 23 2015 23:13
good night!
Steven Kirk
@grokys
Feb 23 2015 23:22
so if I understand it correctly, "ambient contexts" is just a fancy way of saying "static properties"?
but they actually call Locator.GetService - is the idea that we cut out the middle-man and just assign directly to FocusManager.Instance to register the service?