These are chat archives for AvaloniaUI/Avalonia

6th
Aug 2018
Festelo Tawer
@w00psen_twitter
Aug 06 2018 01:22
How to make Grid with dynamic row and column count? Replacement for UniformGrid.
Kyiv
@_VeTaLkO__twitter
Aug 06 2018 13:27
Is ViewLocator used in the app and how to bind VM to the view?

For the main window, it is set by
BuildAvaloniaApp().Start<MainWindow>(() => new MainWindowViewModel());

How can i set for other views/usercontrols?

danwalmsley
@danwalmsley
Aug 06 2018 13:31
@_VeTaLkO__twitter you don't normally need to set it for others, normally your other views are child to the main view
and you bind child controls datacontext to a property
i.e.
Kyiv
@_VeTaLkO__twitter
Aug 06 2018 13:32
Yep, for example i have a UserControl and i want some logic behind it (in its VM)
danwalmsley
@danwalmsley
Aug 06 2018 13:33
[xaml]
<Window Title="MainWindow">
    <MyUserControl DataContext="{Binding UserControl}" />
...
then in
Kyiv
@_VeTaLkO__twitter
Aug 06 2018 13:33
Aha, and UserControl is VM ?
danwalmsley
@danwalmsley
Aug 06 2018 13:33
[c#]
class MainViewModel
{
    public MyUserControlViewModel UserControl {get;}
}
that way you user control gets a data context set to whatever UserControl on main view model is set to
Kyiv
@_VeTaLkO__twitter
Aug 06 2018 13:34
Thanks!
danwalmsley
@danwalmsley
Aug 06 2018 13:34
since window already has its data context set to main view model
it should work :)
Kyiv
@_VeTaLkO__twitter
Aug 06 2018 13:35
And still, about the ViewLocator - is it used (for debugging/previewer) or i can just throw it away?
danwalmsley
@danwalmsley
Aug 06 2018 13:35
you can throw it away
or you can use it :)
Kyiv
@_VeTaLkO__twitter
Aug 06 2018 13:36
Hmm.. :)
danwalmsley
@danwalmsley
Aug 06 2018 13:36
roughly speaking view locator can be used to locate a view based on a viewmodel
and you decide the logic
so in my apps I often have a view locator that
given XViewModel
it loads a view
XView
if you are new to xaml and mvvm id ignore it for now, until you get to a point where you might need it
that point will probably become apparent sooner or later depending on the app your developing
Kyiv
@_VeTaLkO__twitter
Aug 06 2018 13:37
Yep, okay, thanks again! Nah, not that new - just was wondering if its used somehow
danwalmsley
@danwalmsley
Aug 06 2018 13:38
in the templates I believe its unused
its just there because its commonly used