These are chat archives for AvaloniaUI/Avalonia

4th
Feb 2018
James Burnside
@JCBurnside
Feb 04 2018 16:19 UTC
there isn't an equivalent for wpf's status bar yet right?
Nihal Talur
@0xFireball
Feb 04 2018 17:08 UTC
i'm getting OmniXaml.LoadException: Error loading XAML: OmniXaml.ParseException: The type "{:DynamicResourceExtension} cannot be found" trying to use DynamicResource like this:
<ScrollViewer MinWidth="190" Background="{DynamicResource ThemeAccentBrush}" DockPanel.Dock="Left">
Matthijs ter Woord
@mterwoord
Feb 04 2018 17:11 UTC
what avalonia version are you on?
i'd sugest using one of the nightlies..
Nihal Talur
@0xFireball
Feb 04 2018 17:45 UTC
I'm using 0.5.1 "stable"-ish
Matthijs ter Woord
@mterwoord
Feb 04 2018 17:47 UTC
from the myget or nuget?
Nihal Talur
@0xFireball
Feb 04 2018 17:51 UTC
nuget
ah, perhaps DynamicResource was added since the stable release
i'm trying the nightlies now
Matthijs ter Woord
@mterwoord
Feb 04 2018 17:51 UTC
a lot ahs happened sionce latest stable release
most nightlies are quite stable as well though
Nihal Talur
@0xFireball
Feb 04 2018 17:51 UTC
oh ok great
it works, thank you
i guess i'll just stick to the nightlies
Matthijs ter Woord
@mterwoord
Feb 04 2018 17:54 UTC
if you're interested, i got some .target files which can help you switfh you project voer to custom-built avalonia (ie, from sources) easily
Nihal Talur
@0xFireball
Feb 04 2018 17:54 UTC
I don't think i'll need it for this project, but sure, for future reference
Adam Ralph
@adamralph
Feb 04 2018 17:58 UTC
where I can I see an example of showing data in a grid?
Adam Ralph
@adamralph
Feb 04 2018 21:32 UTC
OK, scratch that. What I really need to do is create a DataTemplate through code
The best WPF-flavoured reference I've found so far is https://www.codeproject.com/Articles/444371/Creating-WPF-Data-Templates-in-Code-The-Right-Way but I can't figure out how to do the equivalent in Avalonia
Adam Ralph
@adamralph
Feb 04 2018 22:04 UTC
OK, I got it: var template = (DataTemplate)new AvaloniaXamlLoader().Load(xaml);
somewhat easier than that WPF example :-)
Steven Kirk
@grokys
Feb 04 2018 22:26 UTC
you can then use bindings in the object initializer as described here: http://avaloniaui.net/spec/binding-from-code.html
an example might be:
new FuncDataTemplate<MyViewModel>(x => new TextBlock
{
    [!TextBlock.TextProperty] = new Binding("Foo") // Binds to MyViewModel.Foo
});
Nihal Talur
@0xFireball
Feb 04 2018 22:31 UTC
using ReactiveCommand.CreateFromTask
Adam Ralph
@adamralph
Feb 04 2018 22:31 UTC
@grokys awesome, thanks. That's even better
Nihal Talur
@0xFireball
Feb 04 2018 22:31 UTC
i'm having
{System.InvalidOperationException: Call from invalid thread

My view's datacontext is a viewmodel like this:

loginCommand = ReactiveCommand.CreateFromTask(login);

private async Task login() {
    // TODO: stuff and things
    await Task.Delay(1000);
}

And the command is bound to a Button's command;
but when the button is pressed, I get this exception:

{System.InvalidOperationException: Call from invalid thread
   at Avalonia.Threading.Dispatcher.VerifyAccess()
   at Avalonia.AvaloniaObject.VerifyAccess()
   at Avalonia.AvaloniaObject.GetValue(AvaloniaProperty property)
   at Avalonia.AvaloniaObject.GetValue[T](AvaloniaProperty`1 property)
   at Avalonia.Controls.Button.get_CommandParameter()
   at Avalonia.Controls.Button.CanExecuteChanged(Object sender, EventArgs e)
   at ReactiveUI.ReactiveCommand.OnCanExecuteChanged()
   at ReactiveUI.ReactiveCommand`2.<.ctor>b__9_5(Boolean _)
   at System.Reactive.AnonymousSafeObserver`1.OnNext(T value)
   at System.Reactive.Linq.ObservableImpl.RefCount`1._.OnNext(TSource value)
   at System.Reactive.Subjects.FastImmediateObserver`1.EnsureActive(Int32 count)
   at System.Reactive.Subjects.FastImmediateObserver`1.EnsureActive()
   at System.Reactive.Subjects.ReplaySubject`1.ReplayBase.OnNext(T value)
   at System.Reactive.Subjects.ReplaySubject`1.OnNext(T value)
   at System.Reactive.Linq.ObservableImpl.AsObservable`1._.OnNext(TSource value)
   at System.Reactive.Linq.ObservableImpl.DistinctUntilChanged`2._.OnNext(TSource value)
   at System.Reactive.Linq.ObservableImpl.CombineLatest`3._.S.OnNext(TSecond value)
   at System.Reactive.Linq.ObservableImpl.RefCount`1._.OnNext(TSource value)
   at System.Reactive.Subjects.FastImmediateObserver`1.EnsureActive(Int32 count)
   at System.Reactive.Subjects.FastImmediateObserver`1.EnsureActive()
   at System.Reactive.Subjects.ReplaySubject`1.ReplayBase.OnNext(T value)
   at System.Reactive.Subjects.ReplaySubject`1.OnNext(T value)
   at System.Reactive.Linq.ObservableImpl.AsObservable`1._.OnNext(TSource value)
   at System.Reactive.Linq.ObservableImpl.DistinctUntilChanged`2._.OnNext(TSource value)
   at System.Reactive.Linq.ObservableImpl.Concat`1._.OnNext(TSource value)
   at System.Reactive.Linq.ObservableImpl.Select`2._.OnNext(TSource value)
   at System.Reactive.SafeObserver`1.OnNext(TSource value)
   at System.Reactive.ScheduledObserver`1.Dispatch(ICancelable cancel)
   at System.Reactive.Concurrency.Scheduler.<>c.<ScheduleLongRunning>b__72_0(Action`1 a, ICancelable c)
   at System.Reactive.Concurrency.DefaultScheduler.LongRunning.<>c__DisplayClass1_0`1.<ScheduleLongRunning>b__0(Object arg)
   at System.Reactive.Concurrency.ConcurrencyAbstractionLayerImpl.<>c__DisplayClass7_0.<StartThread>b__0()
   at System.Threading.Thread.ThreadMain_ThreadStart()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()}
Steven Kirk
@grokys
Feb 04 2018 22:37 UTC
you're trying to access controls from a background thread, which isn't allowed
Nihal Talur
@0xFireball
Feb 04 2018 22:37 UTC
where am I doing that?
Steven Kirk
@grokys
Feb 04 2018 22:38 UTC
hard to say without seeing the code, but if you debug your code in VS and look in the Threads window, you should see that you're not on the main thread
System.Threading.ThreadHelper.ThreadStart()
Nihal Talur
@0xFireball
Feb 04 2018 22:39 UTC
but the method is actually empty
all it does is call the task delay
there's no access of controls as far as I know
Steven Kirk
@grokys
Feb 04 2018 22:39 UTC
what thread are you in at the start of the method?
Nihal Talur
@0xFireball
Feb 04 2018 22:39 UTC
the CreateFromTask is called in the constructor
Steven Kirk
@grokys
Feb 04 2018 22:40 UTC
ah it looks like the command's CanExecute state is being changed from a b/g thread
Nihal Talur
@0xFireball
Feb 04 2018 22:41 UTC
is there anything I can do about that?
I don't think i'm specifying a CanExecute
Steven Kirk
@grokys
Feb 04 2018 22:42 UTC
hmm not sure tbh - this is all ReactiveUI code, not avalonia
Nihal Talur
@0xFireball
Feb 04 2018 22:43 UTC
does Avalonia provide any ICommand implementations?
Steven Kirk
@grokys
Feb 04 2018 22:43 UTC
i wonder if CreateFromTask just doesn't work with avalonia?
no, i recommend reactiveui, but it looks like there's something wrong there
let me debug and see if i can work out what's going on
Nihal Talur
@0xFireball
Feb 04 2018 22:44 UTC
cool
thanks
Jeremy Koritzinsky
@jkoritzinsky
Feb 04 2018 22:45 UTC
Are you using the nightly build?
Nihal Talur
@0xFireball
Feb 04 2018 22:46 UTC
yes
I am using the latest package from the avalonia ci nuget feed
Steven Kirk
@grokys
Feb 04 2018 22:50 UTC
hmm yeah i'm seeing the same
Nihal Talur
@0xFireball
Feb 04 2018 22:51 UTC
so is the issue part of reactiveui?
Steven Kirk
@grokys
Feb 04 2018 22:51 UTC
ReactiveCommand.CreateFromTask(Login, outputScheduler: AvaloniaScheduler.Instance) looks like it might fix it
but i don't understand why it's not working by default...
Nihal Talur
@0xFireball
Feb 04 2018 22:52 UTC
i'll try that for now
Steven Kirk
@grokys
Feb 04 2018 22:53 UTC
there seems to be a bug there too where the button looks like it's disabled after the command has been run, it only shows the enabled state again after you move your mouse over it
Nihal Talur
@0xFireball
Feb 04 2018 22:53 UTC
yes
i just noticed that too
i'm trying with a CanExecute now
yeah, something similar for that too
when canexecute is false, the button still appears to be enabled until you mouse over it
but it doesn't kind of "fade out" to the disabled color, you just can't click it
i can make a recording of the behavior if you want
oh, the button appears to switch to the disabled color if you attempt to click it
Steven Kirk
@grokys
Feb 04 2018 22:57 UTC
ahhh ok, i know why the original problem was happening. you need to call UseReactiveUI on your AppBuilder to configure rxui
public static AppBuilder BuildAvaloniaApp()
            => AppBuilder.Configure<App>()
                .LogToDebug()
                .UsePlatformDetect()
                .UseReactiveUI();
Nihal Talur
@0xFireball
Feb 04 2018 22:58 UTC
oops
here is a recording of the button state issue
the button is supposed to be disabled when the username field is empty
Steven Kirk
@grokys
Feb 04 2018 22:59 UTC
yeah it looks like changing the button enabled state doesn't invalidate the visual
Nihal Talur
@0xFireball
Feb 04 2018 22:59 UTC
I added UseReactiveUI, that solves the threading problem, but not this one
can I manually invalidate it?
Steven Kirk
@grokys
Feb 04 2018 23:00 UTC
yeah, i can fix it now
Nihal Talur
@0xFireball
Feb 04 2018 23:00 UTC
sounds good, thanks
are the nuget packages automatically published after every CI build?
Steven Kirk
@grokys
Feb 04 2018 23:00 UTC
only when a PR is merged to master
Nihal Talur
@0xFireball
Feb 04 2018 23:02 UTC
oh ok
Steven Kirk
@grokys
Feb 04 2018 23:02 UTC
hmm, looks like the button problem isn't what i thought it would be
Steven Kirk
@grokys
Feb 04 2018 23:10 UTC
ahh, ok i think i see it, working on a fix now
Nihal Talur
@0xFireball
Feb 04 2018 23:13 UTC
what was the problem?
Steven Kirk
@grokys
Feb 04 2018 23:20 UTC
it was introduced by this AvaloniaUI/Avalonia#1306
because render layers aren't always being created for transparent controls, we need to make sure that all child controls are re-rendered
i think ;)