Avalonia: XAMLIL: Unable to find suitable setter or adder for property Resources...

Created on 22 Oct 2019  ·  4Comments  ·  Source: AvaloniaUI/Avalonia

Hello!
Recently, I update Avalonia on my project to nightly build (now preview build Avalonia 0.9.0-preview3) and some problems has appeared. For example, _commas_ doesn't work anymore at selectors in styles.
But main problem in Resource.
Before update, I used to store some ControleTemplates in UserControl.Resources:
<ControlTemplate x:Key="VisualBlockTemplateParent" TargetType="ListBoxItem">
Now, when I try to build project, I get an error:

image

How can i solve this problem?

bug xaml-compiler

Most helpful comment

Did this resolution make it into build 0.9.1? I just upgraded to the "latest" version and I am getting this same error.

<PackageReference Include="Avalonia" Version="0.9.1" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.1" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.1" />
<PackageReference Include="MessageBox.Avalonia" Version="0.9.0" />

All 4 comments

@MiKaMaru can you please post the Xaml where you declare you ControlTemplates?

@danwalmsley, sure.

Prepare yourself: bad code ahead

` x:Class="GUI.CardControls.Views.ExtendableGroupEditor"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

    <Style Selector="ListBoxItem:selected /template/ ContentPresenter">
        <Setter Property="Background" Value="{DynamicResource ListBoxBrush}" />
    </Style>

    <Style Selector="ListBoxItem:selected:focus /template/ ContentPresenter">
        <Setter Property="Background" Value="{DynamicResource ListBoxBrush}" />
    </Style>

    <Style Selector="ListBoxItem:selected:pointerover /template/ ContentPresenter">
        <Setter Property="Background" Value="{DynamicResource ListBoxBrush}" />
    </Style>

    <Style Selector="ListBoxItem:selected:focus:pointerover /template/ ContentPresenter">
        <Setter Property="Background" Value="{DynamicResource ListBoxBrush}" />
    </Style>

    <Style Selector="TextBlock.OrderText">
        <Setter Property="FontSize" Value="12" />
        <Setter Property="FontWeight" Value="500" />
        <Setter Property="Margin" Value="0 5 0 0" />
    </Style>

</UserControl.Styles>
<UserControl.Resources>
    <ControlTemplate x:Key="VisualBlockTemplateParent" TargetType="ListBoxItem">
        <Grid
            Margin="0,5,0,0"
            Focusable="False"
            RowDefinitions="Auto,*">
            <StackPanel Grid.Row="0">
                <Rectangle Classes="dividingStripGroupEditor" IsVisible="{Binding $parent[UserControl].IsVisibleDividingStrip}" />
                <StackPanel Focusable="False" Orientation="Horizontal">
                    <TextBlock
                        Margin="30,5,0,0"
                        Classes="OrderText"
                        FontWeight="Bold"
                        Text="Запись № " />
                    <TextBlock
                        Classes="OrderText"
                        FontWeight="Bold"
                        Text="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                    <TextBlock
                        Classes="OrderText"
                        FontWeight="Bold"
                        Text="." />
                </StackPanel>
            </StackPanel>
            <Grid Grid.Row="1">
                <ContentPresenter
                    Grid.Column="0"
                    Content="{TemplateBinding Content}"
                    ContentTemplate="{TemplateBinding ContentTemplate}" />
            </Grid>
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="VisualBlockTemplateWithoutDelButton" TargetType="ListBoxItem">
        <Grid Focusable="False" RowDefinitions="Auto,*">
            <StackPanel
                Grid.Row="0"
                Focusable="False"
                Orientation="Horizontal">
                <TextBlock
                    Margin="30,5,0,0"
                    Classes="OrderText"
                    FontWeight="Bold"
                    Text="Запись № " />
                <TextBlock
                    Classes="OrderText"
                    FontWeight="Bold"
                    Text="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                <TextBlock
                    Classes="OrderText"
                    FontWeight="Bold"
                    Text="." />
            </StackPanel>
            <Grid Grid.Row="1">
                <ContentPresenter
                    Grid.Column="0"
                    Content="{TemplateBinding Content}"
                    ContentTemplate="{TemplateBinding ContentTemplate}" />
            </Grid>
        </Grid>
    </ControlTemplate>
</UserControl.Resources>
<Grid HorizontalAlignment="Left" RowDefinitions="*,Auto">
    <ListBox
        Name="ListBox1"
        Grid.Row="0"
        Margin="-4,0,0,0"
        Background="{DynamicResource ListBoxBrush}"
        BorderThickness="0"
        VirtualizationMode="None" />
    <StackPanel
        Grid.Row="1"
        Margin="0,0,0,5"
        Orientation="Vertical">
        <Button
            Name="AddReq"
            Width="80"
            Height="25"
            Margin="30,0,0,0"
            HorizontalAlignment="Left">
            Добавить
        </Button>
        <Rectangle Name="DividingStripRectangle" Classes="dividingStripGroupEditor" />
    </StackPanel>
</Grid>


`

We have some logic with
public ControlTemplate VisualBlockTemplateParent => (ControlTemplate)this.FindResource(nameof(VisualBlockTemplateParent));
on back-side. that's why I need it.
Even if I try to do smth like this in empty Avalonia Project on 0.9.0-preview3 - I can not build it.

x:Key in ControlTemplate - hasn't setter for this anymore

Did this resolution make it into build 0.9.1? I just upgraded to the "latest" version and I am getting this same error.

<PackageReference Include="Avalonia" Version="0.9.1" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.1" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.1" />
<PackageReference Include="MessageBox.Avalonia" Version="0.9.0" />
Was this page helpful?
0 / 5 - 0 ratings

Related issues

TheColonel2688 picture TheColonel2688  ·  3Comments

MarchingCube picture MarchingCube  ·  4Comments

RUSshy picture RUSshy  ·  4Comments

Suriman picture Suriman  ·  3Comments

GitHubington picture GitHubington  ·  3Comments