These are chat archives for AvaloniaUI/Avalonia

26th
Jan 2019
nicolasr75
@nicolasr75
Jan 26 00:30

Just tried the newest build with this dummy xaml on Windows 10

<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="AvaloniaTest" Width="300" Height="200"> </Window>

and get a black margin on the top and left while the (empty) window content is white and shifted right/bottom. As soon as I resize the window by a few pixels, the window content is correctly top/left aligned, i.e. the black margin disappears. Can anyone reproduce this?

stropheum
@stropheum
Jan 26 00:51
thank you @grokys !<3
stropheum
@stropheum
Jan 26 02:22
Also this might be silly but i couldn't find in the docs explicitly how to do this.
1) Is it possible to create a composite template? I have a stack panel containing two textblocks and a button that I want to template in code
2) how would i access say, a vertical stack panel or list box via code and dynamically add these templated elements to it?
stropheum
@stropheum
Jan 26 02:31
I suppose the latter i would just follow the docs for that right
<ListBox Items="{Binding Items}"/>
And i would append the template to items? I guess I was curious if there was a way, or if i should even be thinking in terms of trying to grab a ListBox item itself
Scrollview probably rather* not listbox
ahopper
@ahopper
Jan 26 03:18
@nicolasr75 are you sure you are on the latest build? there is a sorting issue on myget and builds >=1000 are near the bottom of the list
James Burnside
@JCBurnside
Jan 26 03:58
given I have the following UserControl how would I bind to something from the root object (UserControl) from inside a DataTemplate
<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Class="CanvasTesting.Views.Star">
    <ItemsControl Items="{Binding Lines}">
        <!--...-->
<ItemsControl.DataTemplates>
            <DataTemplate>
                <Line StartPoint="{Binding Start}" EndPoint="{Binding End}" Stroke="{Binding $parent[UserControl].Stroke}"/>
            </DataTemplate>
        </ItemsControl.DataTemplates>
    </ItemsControl>
</UserControl>
I am trying to bind Stroke to the Stroke prop of the control.
nicolasr75
@nicolasr75
Jan 26 11:06
@ahopper I used what the nuget manager offered me which is 0.7.1-build989. I started with 0.7.0 and everything looks fine. Then I update and the margins appear. I will open an issue in Github to show some screenshots...
ahopper
@ahopper
Jan 26 11:08
there are newer builds than 989 with this fixed I think
if you scroll down in the nuget manager list there are higher numbers near the bottom!
nicolasr75
@nicolasr75
Jan 26 11:13
Oh yeah, just seeing it. Thanks. Somewhat confusing that the nuget manager now keeps asking me for updating with older builds...
@ahopper btw, the issue is gone with the newest build
Steven Kirk
@grokys
Jan 26 11:19
@nicolasr75 yeah, it's annoying. see AvaloniaUI/Avalonia#2217 for discussion around the issue
ahopper
@ahopper
Jan 26 11:20
yep, typical that it chose a version with particularly irritating issues to stop on :)
MonkAlex
@MonkAlex
Jan 26 13:50
Anyone has loading spinner for avalonia? I try to use progress bar, but its broken now
MonkAlex
@MonkAlex
Jan 26 13:58
WPF use Storyboard for this, but not found it in avalonia
Steven Kirk
@grokys
Jan 26 14:00
@MonkAlex what's broken about progress bar?
MonkAlex
@MonkAlex
Jan 26 14:00
Steven Kirk
@grokys
Jan 26 14:00
you're right we don't have storyboards, we have an animation system more similar to CSS: http://avaloniaui.net/docs/animations/
ah i thought #2015 was fixed :(
i will take a look into that
MonkAlex
@MonkAlex
Jan 26 14:17
Animation is hard :D No idea, how to write it. Has any examples?
James Burnside
@JCBurnside
Jan 26 14:24
So inside DataTemplate for an ItemsTemplate how do I access the root DataContext?
ahopper
@ahopper
Jan 26 14:26
$parent[parent type].DataContext
James Burnside
@JCBurnside
Jan 26 14:32
Ah ok.
James Burnside
@JCBurnside
Jan 26 15:02
ok so here is my current code https://gist.github.com/JCBurnside/14efbe8e728ec302cd157eb004775764 . it seems to try to use the DataContext of where it is used not the Star's own context
I am trying to bind to the StyledProperty Stroke
ahopper
@ahopper
Jan 26 15:23
what is the DataContext of the usercontrol, it is typically inherited from the enclosing view's DataContext
James Burnside
@JCBurnside
Jan 26 15:24
I don't set one. so it inherits where it is used? that seems a little counter-intuitive to me.
so how would I use a bind to a prop I defined in Star.xaml.cs then?
ahopper
@ahopper
Jan 26 15:26
it makes good sense normally:) you could set the datacontext of an internal part (xaml control) to this in code behind, that way you have access to the inherited datacontext and the private code behind one
James Burnside
@JCBurnside
Jan 26 15:27
wdym?
I thought that each control has an isolated DataContext that way it wouldn't read from the containing viewmodel.
ahopper
@ahopper
Jan 26 15:30
if you name your outer stackpanel and use findControl and set its DataContext to this in the constuctro
by default they inherit the containers dc, you can bind the dc to some item of the vm in xaml
James Burnside
@JCBurnside
Jan 26 15:32
but if I want to self vm I would have to do codebehind wouldn't I?
ahopper
@ahopper
Jan 26 15:34
you are effectively putting a vm in your codebehind, in which case you probably have to also set dc in code behind
James Burnside
@JCBurnside
Jan 26 15:36
got it. still seems weird to me that you can essentially leak a dc into a UserControl
ahopper
@ahopper
Jan 26 15:36
it is best not to set the dc directly on the UserControl as that makes passing parameters in odd (or it does in wpf) so it is common to set it on the first child of usercontrol
in proper mvvm it is not a leak it is just right
James Burnside
@JCBurnside
Jan 26 15:38
so I can do this.FindControl<StackPanel>("Container").DataContext = this; in the ctor to set the dc to the current instance right?
ahopper
@ahopper
Jan 26 15:39
yep
James Burnside
@JCBurnside
Jan 26 15:40
hm... still giving me Binding: Error in binding to "Avalonia.ValueStore"."Stroke": "Null value in expression '$parent[StackPanel, 0]'."
I will try binding to a named control instead.
ahopper
@ahopper
Jan 26 15:41
you can get those errors but it still works
binding to named controls from inside templates doesnt work
James Burnside
@JCBurnside
Jan 26 15:42
really? bug?
also binding errors are sometimes emitted when everything is basically fine
James Burnside
@JCBurnside
Jan 26 15:54
I must still be doing something wrong. I updated the gist.
no lines are showing up.
ahopper
@ahopper
Jan 26 15:57
the Items binding does not need all the $parent stuff
but that won't break it
James Burnside
@JCBurnside
Jan 26 15:57
I tried it both ways
Did I mess up the LinesProperty declaration?
ahopper
@ahopper
Jan 26 16:03
At a quick glance I can't see anything, maybe put a load of break points in to see what is and isn't called
stropheum
@stropheum
Jan 26 17:01
I just noticed a thing. btw. not sure if this is a bug or just left out of the docs
I basically created this setup verbatim, just using my own namespace and "FileUploadData" instead of "Student"
I kept getting an error "no constructor found for supplied arguments".
I was able to get this working by explicitly declaring a default constructor. I suppose instead of constructing the object, it's default constructing it and setting the fields individually. If that's the case, maybe the docs should reflect that whatever models you're using, you should either declare no constructor so the default one gets provided under the hood, or explicitly declare one
Nikita Tsukanov
@kekekeks
Jan 26 19:01
@grokys https://github.com/AvaloniaUI/Avalonia/pull/2269/files - simple solution for nuget versioning
"c" is greater than "b", so "cibuild" will treated a a newer one
stropheum
@stropheum
Jan 26 19:25

So here's a question, for anything happening asynchronously, for example in my viewmodel I have a background process that monitors files being added to directories, and fires of an async call to a server when that happens.

Now that I've added code to dynamically add UI components, this is causing that process to throw
System.InvalidOoperationException: 'Call from invalid thread'

Should I be using the avalonia dispatcher to fire off that async/await stuff? and how would I do that if I already have an async function that i simply want to await?
This is the signature for example
private async Task<Newtonsoft.Json.Linq.JObject> CreateFileOnServerAsync(VideoData data)

Jeremy Koritzinsky
@jkoritzinsky
Jan 26 19:35
Yeah any changes to bindable properties on an AvaloniaObject-derived object need to be done on the UI thread. You could always await your call and then queue the update on the Dispatcher afterwards
stropheum
@stropheum
Jan 26 19:39
Oh i didn't know you could queue that update. what does that look like?
stropheum
@stropheum
Jan 26 19:51
Oh nvm I think I see what I'm doing. I invoke a callback event for OnFileCreated which is coming from an async state. I think if i just put that invocation after my await, they shouldn't bump into one another
stropheum
@stropheum
Jan 26 20:18
Oh I figured it out!
Avalonia.Threading.Dispatcher.UIThread.Post(
                () => AddFileDataTile(e.FileName, e.FileUrl), 
                Avalonia.Threading.DispatcherPriority.Normal);
that worked to sort of "escape" my async thread. Unfortunately I couldn't just await everything, because I'm using a third party tool and I have to hook it into an async callback the way I have it set up. So this was a nice way for me to do it
Benedikt Schroeder
@Gillibald
Jan 26 21:06
Direct2D1 Direct2D1Inlines.JPG
Skia SkiaInlines.JPG
Skia handles brush sizes correctly and Direct2D1 doesn't
Alexander Gnauck
@agnauck
Jan 26 21:09
:thumbsup:
ahopper
@ahopper
Jan 26 21:22
so is this a brush shared across a number of inlines?
Benedikt Schroeder
@Gillibald
Jan 26 22:28
Brushes are applied per run within the text layout
A run consists of characters with the same properties like size foreground etc