C
C#4mo 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
leowest4mo 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
Mekasu01244mo 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
leowest4mo 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
Mekasu01244mo ago
it did have them, but I haven't needed them. I have it setup like
leowest
leowest4mo ago
u have a viewlocator
Mekasu0124
Mekasu01244mo 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
leowest4mo ago
ah ok
Mekasu0124
Mekasu01244mo 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
leowest4mo ago
well glad u figured it out 😉
Mekasu0124
Mekasu01244mo 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
leowest4mo ago
I like it, its really nice imo very light weight $close
MODiX
MODiX4mo ago
Use the /close command to mark a forum thread as answered