C
C#10mo ago
Mekasu0124

✅ Switching from ReactiveUI to CommunityToolkit

<Window xlmns="https://github.com/avaloniaui"
xlmns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Diary.Views.MainWindowView"
Icon="/Assets/logo.ico"
Width="1500"
Height="850"
Title="Diary"
Content="{Binding Content}"
WindowStartupLocation="CenterScreen">
</Window>
<Window xlmns="https://github.com/avaloniaui"
xlmns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Diary.Views.MainWindowView"
Icon="/Assets/logo.ico"
Width="1500"
Height="850"
Title="Diary"
Content="{Binding Content}"
WindowStartupLocation="CenterScreen">
</Window>
I'm using CommunityToolkit now and I'm getting the error on the line Content="{Binding Content}"
AVLN:00C Cannot parse a compiled binding without an explicit x:DataType directive to give a starting data type for bindings
AVLN:00C Cannot parse a compiled binding without an explicit x:DataType directive to give a starting data type for bindings
and I'm not sure what to do. This works just fine in ReactiveUI
12 Replies
leowest
leowest10mo ago
<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:MainViewModel />
</Design.DataContext>
<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:MainViewModel />
</Design.DataContext>
and inside the window
x:DataType="vm:MainViewModel"
x:DataType="vm:MainViewModel"
assuming that is what your mainwindowview viewmodel is called and xmlns:vm="using:Diary.ViewModels"
Mekasu0124
Mekasu0124OP10mo ago
I just figured it out. I had to edit the project's file
- <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
+ <AvaloniaUseCompiledBindingsByDefault>false</AvaloniaUseCompiledBindingsByDefault>
- <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
+ <AvaloniaUseCompiledBindingsByDefault>false</AvaloniaUseCompiledBindingsByDefault>
leowest
leowest10mo ago
ok but are u not missing those? the default Avalonia template with CTK generate those above I listed also my default binding is set to true
Mekasu0124
Mekasu0124OP10mo ago
it did have them, but I haven't needed them. I have it setup like
leowest
leowest10mo ago
u have a viewlocator
Mekasu0124
Mekasu0124OP10mo ago
<Window ...
Content = "{Binding Content}">
...
<Window ...
Content = "{Binding Content}">
...
public MainWindowViewModel : ViewModelBase
{
ViewModelBase _content;

public MainWindowViewModel() {}
public void Update(...)
{
Content = new UpdateAvailableViewModel(...);
}
}
public MainWindowViewModel : ViewModelBase
{
ViewModelBase _content;

public MainWindowViewModel() {}
public void Update(...)
{
Content = new UpdateAvailableViewModel(...);
}
}
when I was using reactive ui
leowest
leowest10mo ago
ah ok
Mekasu0124
Mekasu0124OP10mo ago
yea. the main window view model is built to serve as the window manager for the application every screen shows within the main window and the main window just knows when to show what screen based off what user interaction
leowest
leowest10mo ago
well glad u figured it out 😉
Mekasu0124
Mekasu0124OP10mo ago
thanks. Althought Community Toolkit removes a lot of boiler plate, I just hope it's not too much of a headache to work with
leowest
leowest10mo ago
I like it, its really nice imo very light weight $close
MODiX
MODiX10mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server