Untitled
unknown
plain_text
8 months ago
2.0 kB
4
Indexable
🔍 What this means:
You're trying to apply a UI property like HorizontalAlignment="Right" on something that is not a control, specifically on:
<ControlTheme x:Key="DockPanelTitleTemplate" TargetType="{x:Type dashboard:DashboardViewModel}">
But DashboardViewModel is a ViewModel, not a visual control like Button, StackPanel, etc.
🔥 Problem: You're declaring a <ControlTheme> with TargetType="{x:Type DashboardViewModel}" — but that's invalid.
A ControlTheme in Avalonia must target a visual control type (e.g., Button, ComboBox, ContentControl, etc.), not a ViewModel class.
âś… Solutions:
âś… Option 1: Change TargetType to an actual Control
If this block is meant to define a control’s appearance (like a ContentControl that uses a DashboardViewModel as DataContext), then change this:
<ControlTheme x:Key="DockPanelTitleTemplate" TargetType="{x:Type dashboard:DashboardViewModel}">
to:
<ControlTheme x:Key="DockPanelTitleTemplate" TargetType="ContentControl">
Then apply the template to a ContentControl that uses DashboardViewModel as its content.
Example usage:
<ContentControl Content="{Binding DashboardViewModel}" Style="{StaticResource DockPanelTitleTemplate}" />
This way, you apply that control template to a ContentControl, not to the ViewModel itself.
âś… Option 2: If this was intended as a DataTemplate, not a ControlTheme
It's likely you're trying to do this:
<DataTemplate DataType="{x:Type dashboard:DashboardViewModel}">
<!-- your layout here -->
</DataTemplate>
So change:
<ControlTheme x:Key="DockPanelTitleTemplate" TargetType="{x:Type dashboard:DashboardViewModel}">
➡ to:
<DataTemplate DataType="{x:Type dashboard:DashboardViewModel}">
✔ This is the correct approach if you’re using ContentControl.ContentTemplate.
🔚 Summary:
What You Have What You Likely Need
ControlTheme targeting a ViewModel DataTemplate (if showing ViewModel)
ControlTheme for visuals Should target a control like ContentControl, Border, etc.
Editor is loading...
Leave a Comment