These are chat archives for AvaloniaUI/Avalonia

30th
Dec 2017
James Burnside
@JCBurnside
Dec 30 2017 02:55
hello!
I am very new to avalonia and am trying to find some good examples of how do various things such as binding to a TextBlock to a Writer/Stream
James Burnside
@JCBurnside
Dec 30 2017 03:30
I suppose I mean reader instead of writer
Pavel Tupitsyn
@ptupitsyn
Dec 30 2017 17:34
Hi! Android support is mentioned, is there an example or a tutorial of any kind?
Pavel Tupitsyn
@ptupitsyn
Dec 30 2017 17:40
Thanks!
James Burnside
@JCBurnside
Dec 30 2017 18:40
is binding from the XAML working?
Matthijs ter Woord
@mterwoord
Dec 30 2017 18:40
yes!
James Burnside
@JCBurnside
Dec 30 2017 18:42
so the example isn't clear. is just a variable in the class you can bind to or do you have to set something specific?
Matthijs ter Woord
@mterwoord
Dec 30 2017 18:42
you have to make avalonia properties.
James Burnside
@JCBurnside
Dec 30 2017 18:43
ah ok. how do I do that?
Matthijs ter Woord
@mterwoord
Dec 30 2017 18:43
already looking for the doc..
are you familiar with wpf?
James Burnside
@JCBurnside
Dec 30 2017 18:44
unfortunately not beyond name.
Matthijs ter Woord
@mterwoord
Dec 30 2017 18:44
uwp/xamarin?
James Burnside
@JCBurnside
Dec 30 2017 18:44
no. I am new to ui in general
Nikita Tsukanov
@kekekeks
Dec 30 2017 18:44
Your view model needs to support INotifyPropertyChanged interface
Nikita Tsukanov
@kekekeks
Dec 30 2017 18:45
It's not needed for binding source
only for binding target (e. g. TextBox)
James Burnside
@JCBurnside
Dec 30 2017 18:45
ok.
I am still not quite sure how to go about this. but I am trying to bind an IObservable<string> to a TextBox text
Nikita Tsukanov
@kekekeks
Dec 30 2017 18:50
You need to create a view model
which implements INotifyPropertyChanged
and has public IObservable<string> Text {get;set;} property
Then you can <TextBox Text="{Binding Text}"/>
It will be a one-way binding, though
James Burnside
@JCBurnside
Dec 30 2017 18:52
{
oops
James Burnside
@JCBurnside
Dec 30 2017 19:30
ok so I am new to the MVVM style is the VM is the class that we run AvaloniaXamlLoader.Load(this) in right?
jp2masa
@jp2masa
Dec 30 2017 19:31
that's the view
James Burnside
@JCBurnside
Dec 30 2017 19:32
I thought that was Xaml
jp2masa
@jp2masa
Dec 30 2017 19:32
the view is both the xaml and the xaml.cs (which is the code-behind)
then there's the DataContext property
when using a view model, you assign an instance of the view model to DataContext
James Burnside
@JCBurnside
Dec 30 2017 19:34
ah ok
the viewmodel can be a struct right?
jp2masa
@jp2masa
Dec 30 2017 19:36
it should be a class I think
which implements INotifyPropertyChanged
James Burnside
@JCBurnside
Dec 30 2017 19:39
So I have a class view model with INotifyPropertyChanged
and the variable test which is an IObservable<string>
then in the xaml I can do <TextBlock Name="Output" Text="{Binding test}"/> and it should work as long as I set DataContext to an instance of view model?
jp2masa
@jp2masa
Dec 30 2017 19:41
not sure if you have to invoke PropertyChanged when test is set
James Burnside
@JCBurnside
Dec 30 2017 19:57
I just did with and without and neither are working
danwalmsley
@danwalmsley
Dec 30 2017 21:13
@JCBurnside here is an example of a view model
It uses reactive ui to do the INPC for you
SetAndRaiseIfChanged notifies ui to update provided something is bound to the property
Nikita Tsukanov
@kekekeks
Dec 30 2017 21:55
It automagically generates property changed invocations when neccessary
James Burnside
@JCBurnside
Dec 30 2017 23:03
What imports the RaseAndSetIfChanged function?
James Burnside
@JCBurnside
Dec 30 2017 23:11
nevermind I found it
James Burnside
@JCBurnside
Dec 30 2017 23:23
it still isn't working right. maybe I didn't make the observable right.