These are chat archives for AvaloniaUI/Avalonia

16th
Aug 2018
danwalmsley
@danwalmsley
Aug 16 2018 06:06
Yes
Ill see if i can get a repro
Sergey
@PurpleGray
Aug 16 2018 13:34
Hi, i've got this property in my VM: public Brush IsConnectedBrush =>
IsConnected ? new SolidColorBrush(Colors.Chartreuse) : new SolidColorBrush(Colors.IndianRed);
Which binded to Background property of some control
At start IsConnected is false, so background set to IndianRed
Then IsConnected is changed, but creation of brush with color Chartreuse throws exception like "Calling from invalid thread"
So color remains the same
I cant call it from Dispatcher thread and return value ofc
because its property
Why SolidColorBrush throws such exception?
As I see in sources, its imposible
So problem is somewhere on level higher (when value is being returned from property?)
With converter story is same
MonkAlex
@MonkAlex
Aug 16 2018 13:46

I cant call it from Dispatcher thread and return value ofc

u can do it in property

Sergey
@PurpleGray
Aug 16 2018 13:51
ofc I can, like this:
            SolidColorBrush brush = null;

            Dispatcher.UIThread.InvokeAsync(() =>
            {
                if (IsConnected)
                {
                    brush = new SolidColorBrush(Colors.Chartreuse);
                }
                else
                {
                    brush = new SolidColorBrush(Colors.IndianRed);
                }
            });

            return brush;
but it will return null
MonkAlex
@MonkAlex
Aug 16 2018 14:48
InvokeAsync do it async. Wait invokeasync result.
Steven Kirk
@grokys
Aug 16 2018 15:19
@Stratocast3r i think you need to set IsConnected on the UI thread
Adam Dusty
@adamdusty
Aug 16 2018 18:15
Is it possible to use WPF toolkits like mahapps with avalonia?
danwalmsley
@danwalmsley
Aug 16 2018 18:32
Unfortunately not compatible
It could be ported to avlonia
Or individual controls or styles
Nicolas Musset
@Kryptos-FR
Aug 16 2018 21:28
@Stratocast3r @MonkAlex after my PR is merged you will be able to do return await Dispatcher.InvokeAsync(() => return new SolidColorBrush()); :smile: