These are chat archives for AvaloniaUI/Avalonia

26th
Apr 2018
se5a
@se5a
Apr 26 2018 11:33
I'm trying to get Avalonia to work in linux targeting net461, my project has a bunch of library that are 461 and not compatible with netstandard or core. Avalonia will run in windows targeting net461 but on linux I'm getting errors complaining about "No rendering subsystem found. Are you missing assembly references?"
Nils Kvist
@budRich
Apr 26 2018 11:34
hello. I would like to try Avalonia out to make a window application that will work on both Linux and Windows. I got the template hello world to work, but now im stuck (i'm quite new to csharp in general).
I have a textbox with : Name="tbTest" ... i want to change the Text of the box from the cs file for the window, but tbTest is not recognized. Feels like im missing something basic and i just need a hint to get past this.
cs file = MainWindow.xaml.cs
i have AvaloniaXamlLoader.Load(this); in the window constructor. and it worked fine with the hello world and other simple tests i did.
but how to access and modify controls dynamically with code?
se5a
@se5a
Apr 26 2018 11:39
oh humn, looks like if the Avalonia project targets netcore2.0 and the other project targets netstandared2.0 which can then reference net461 libs...
danwalmsley
@danwalmsley
Apr 26 2018 11:43
@budRich you need to call var textbox = this.FindControl<TextBox>("tbTest");
our XAML doesn't get generated into cs code like in wpf so the controls do not get defined in code for you
Nils Kvist
@budRich
Apr 26 2018 11:47
@danwalmsley thanks man! This avalonia thing looks very promising, and i have decided to use it for this project, (i am attending a introduction course for .NET, this is my final project)
danwalmsley
@danwalmsley
Apr 26 2018 11:55
@budRich allow me point you to the following example:
your current way of updating the text on the ui isn't the main way avalonia is designed to work.
specifically see in the example we have:
a view model here
with a TextBoxText property
its setter here raises an event to let the UI know the value has changed here
and then you will see very simple ui code shows various ways of binding the ui to that value...
this pattern is known as MVVM (model view viewmodel)
it keeps your UI logic separated from your UI code, this is important to ensure your application remains maintainable as it may grow in future,
and to be able to test your ui logic and your application code sepeately.
I wish I had known this when I was starting out with .net ;)
Nils Kvist
@budRich
Apr 26 2018 12:07
Excellent! this saves me weeks of failing!
danwalmsley
@danwalmsley
Apr 26 2018 12:09
no problem, just ping me a message if you have any other questions, I can quickly knock together more examples and add for you and others :)
Nils Kvist
@budRich
Apr 26 2018 12:12
Cool. I see you are working on an IDE, i am using a windows machine for the sole purpose of UI layout in Visual Studio, but would much rather do everything on Linux. I never managed to get monodevelop working, will give your IDE i try.
danwalmsley
@danwalmsley
Apr 26 2018 12:13
yes, it works reasonably well now
there are a few bugs, but if you want to give it a try I can give you a hand getting set up
as long as you don't mind the odd issue we may encounter
XAML previewer works really well :)
Nils Kvist
@budRich
Apr 26 2018 12:14
if i did i wouldn't develop .Net on linux ;)
danwalmsley
@danwalmsley
Apr 26 2018 12:14
awesome
Nils Kvist
@budRich
Apr 26 2018 12:14
let me just switch pc, i use Arch btw
danwalmsley
@danwalmsley
Apr 26 2018 12:14
Nils Kvist
@budRich
Apr 26 2018 12:15
copy that
Jacob Millward
@JacobMillward
Apr 26 2018 13:29
The documentation mentions change notifications, but links to a 404
danwalmsley
@danwalmsley
Apr 26 2018 13:33
@JacobMillward which page?
Right at the top, in brackets
danwalmsley
@danwalmsley
Apr 26 2018 14:20
looks like no-one has written that page
its basically saying assuming your class implements INotifyPropertyChanged interface
see an example here where reactive ui is used to do this for you
it means that as in this line here:
when the properties value is changed, the ui is notified
and avalonia knows to redraw the control as per the new value of the property
Jacob Millward
@JacobMillward
Apr 26 2018 14:24
That example has no property.
L9 just shows the class inheriting from ViewModelBase
danwalmsley
@danwalmsley
Apr 26 2018 14:25
sorry 3rd link should have been
let me post those again
I messed up
Jacob Millward
@JacobMillward
Apr 26 2018 14:25
Yeah I've figured out to use that, didn't know it was from ReactiveUI
The documentation is really sparse
danwalmsley
@danwalmsley
Apr 26 2018 14:25
we are open to contributions ;)
also feel free to fall back on wpf and uwp documentation
Jacob Millward
@JacobMillward
Apr 26 2018 14:25
I would love to! But I've never used XAML before
danwalmsley
@danwalmsley
Apr 26 2018 14:26
the viewmodel and binding stuff is not specific to avalonia
there are lots of resources available, its taking time to build up documentation for avalonia
Jacob Millward
@JacobMillward
Apr 26 2018 14:26
While I've got you, is there anyway to pre-prococess the XAML? I'm trying to set a different application icon based on the build OS
danwalmsley
@danwalmsley
Apr 26 2018 14:27
in that case Id do something like:
Jacob Millward
@JacobMillward
Apr 26 2018 14:27
Or is that something I'll have to set up myself with a build script
danwalmsley
@danwalmsley
Apr 26 2018 14:27
Icon={Binding AppIcon} in xaml
then on your viewmodel have a property
that returns the icon you want depending on the os
Jacob Millward
@JacobMillward
Apr 26 2018 14:28
Ah ok
ahopper
@ahopper
Apr 26 2018 20:39
Hi has anyone written an avalonia MessageBox ?
danwalmsley
@danwalmsley
Apr 26 2018 20:39
iv made some kind of modal dialog, based on a viewmodel, etc
but not a system dialog one
works quite nicely, as along as you want to do the ui yourself
ahopper
@ahopper
Apr 26 2018 20:41
That sounds useful
Just wading through converting some wpf
danwalmsley
@danwalmsley
Apr 26 2018 20:51
i'll point you to what iv done
ahopper
@ahopper
Apr 26 2018 20:52
cheers
danwalmsley
@danwalmsley
Apr 26 2018 20:53
take a look at this PR
VitalElement/AvalonStudio@4be01de
it should point you in the right direction
mainly OpenCloseWindow behavior
ahopper
@ahopper
Apr 26 2018 20:55
thanks, I've been playing with AvalonStudio a bit, very impressed, there is obviously a lot of work in there.
danwalmsley
@danwalmsley
Apr 26 2018 20:56
cool
let me know if you have any feedback ;)
ahopper
@ahopper
Apr 26 2018 21:02
will do, I released the first alpha of the avalonia version of my SparkSDR radio app into the wild today, there is an abnormally high percentage of Linux users in the amateur radio world and avalonia has made porting my wpf app remarkably easy. A big thanks to all the contributors.
noah the goodra
@jfmherokiller
Apr 26 2018 21:05
just curious does anyone know how to bind the open function of the popup to a button without needing to go to C# code?
ahopper
@ahopper
Apr 26 2018 21:05
yep
@jfmherokiller
<ToggleButton  IsChecked="{Binding #Settings.IsOpen, Mode=TwoWay}" ClickMode="Press"  >
noah the goodra
@jfmherokiller
Apr 26 2018 21:08
@ahopper thanks alot
ahopper
@ahopper
Apr 26 2018 21:08
where your popup is called settings
noah the goodra
@jfmherokiller
Apr 26 2018 21:08
i dont plan to keep it that way tho
this is mainly for testing
eg for wip
im essentially spawning a popup to allow for user input
without well needing to dirty the window with an extra TextBox control
ahopper
@ahopper
Apr 26 2018 21:10
if the popup has StaysOpen="False" it is just like a uwp flyout
noah the goodra
@jfmherokiller
Apr 26 2018 21:11
well i dont know exactly what that is lol funfact I have more of a winforms background and kind of used a tool to convert my ui to wpf and now translating that to xaml supported by Avalonia
@ahopper just googled that flyout thing and yes thats exactly what i was thinking of
ahopper
@ahopper
Apr 26 2018 21:13
uwp flyouts are like the windows 10 dialogs that you dismiss by clicking outside them
noah the goodra
@jfmherokiller
Apr 26 2018 21:17
@ahopper is there any way todo what you presented above with a regular button not a toggle button?
ahopper
@ahopper
Apr 26 2018 21:19
I don't know how to do that without code. The toggle button works neatly because of the twoway binding.
you can always style the togglebutton to look like a normal one
Jacob Millward
@JacobMillward
Apr 26 2018 21:24
@danwalmsley That tip you gave me earlier I can't figure out
I'm creating a WindowIcon object to assign to the Icon field via a binding. But it's not displaying?
public WindowIcon AppIcon => new WindowIcon("resm:AvaloniaApplicationPrototype.Assets.avalonia-logo.ico");
danwalmsley
@danwalmsley
Apr 26 2018 21:28
@JacobMillward I will have a quick try here
Jacob Millward
@JacobMillward
Apr 26 2018 21:29
I've just gotten it working with
public WindowIcon AppIcon => new WindowIcon(Assembly.GetExecutingAssembly().GetManifestResourceStream("AvaloniaApplicationPrototype.Assets.avalonia-logo.ico"));
But that seems messy to me
(Typical that things get sorted just as you ask)
noah the goodra
@jfmherokiller
Apr 26 2018 21:57
how do i set the textbox so that backspace will work without a modifier?
danwalmsley
@danwalmsley
Apr 26 2018 22:31
Backspace should work in TextBox anyhow
noah the goodra
@jfmherokiller
Apr 26 2018 22:40
well atleast on my macbook i guess its a "delete" key instead of a true backspace key. but even then pressing the "delete" key in the textbox doesnt backspace the content like in most osx applications.