question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why am I getting a "Unable to find suitable setter or adder" error when defining a LinearGradientBrush in my <UserControl.Resources>?

See original GitHub issue

Hi:

I’m running into issues defining a LinearGradientBrush in my <UserControl.Resources> in my UserControl.

Here is the XAML Definition:

<UserControl x:Class="SampleViews.SplashView"
             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"
             xmlns:views="clr-namespace:SampleViews"             
             mc:Ignorable="d" >

  <UserControl.Resources>
    <LinearGradientBrush x:Key="LGB1" EndPoint="1,0.5" StartPoint="0,0.5">
      <GradientStop Color="#3F000000" Offset="0"/>
      <GradientStop Offset="1"/>
    </LinearGradientBrush>
  </UserControl.Resources>
     
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width=".2*" />
      <ColumnDefinition Width=".6*" MinWidth="300"/>
      <ColumnDefinition Width=".2*"/>
    </Grid.ColumnDefinitions>
    <Border Grid.Column="0" Background="{StaticResource LGB1}"></Border>
  </Grid>
</UserControl>

Here is the error message:

Error XAMLIL Unable to find suitable setter or adder for property Resources of type Avalonia.Styling:Avalonia.StyledElement for argument Avalonia.Visuals:Avalonia.Media.LinearGradientBrush, available setter parameter lists are: Avalonia.Controls.IResourceDictionary System.Collections.Generic.KeyValuePair`2<System.Object,System.Object>

I should be able to define this resource within the UserControl.Resources to be used throughout the page, correct?

Am I doing something wrong here?

Thanks, JohnB

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jp2masacommented, May 15, 2022

I think the problem is you wrote x:key but it’s x:Key.

0reactions
chenjing1294commented, May 15, 2022

I have the same problem:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="Avalonia.NETCoreMVVMApp1.Views.MainWindow"
        Icon="/Assets/avalonia-logo.ico"
        Title="Controls" Width="250" Height="150">
  <!--FontFamily="Microsoft YaHei"-->
  <Window.Resources>
    <SolidColorBrush x:Key="Warning">Yellow</SolidColorBrush>
  </Window.Resources>
  <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
    <StackPanel>
      <StackPanel.Resources>
        <Bitmap x:key="Play">
          <x:Arguments>
            <x:String>/Assets/play.png</x:String>
          </x:Arguments>
        </Bitmap>
        <Bitmap x:key="Pause">
          <x:Arguments>
            <x:String>/Assets/pause.png</x:String>
          </x:Arguments>
        </Bitmap>
      </StackPanel.Resources>
      <Button Width="160">My Button</Button>
      <Button Width="200" Foreground="White" Background="Red">White text, red background</Button>

      <Button Name="PlayButton" HorizontalAlignment="Center" Width="36" Command="{Binding PlayCommand}">
        <Panel>
          <Image Source="{StaticResource Play}" IsVisible="{Binding !IsPlaying}" Width="20"
                 Height="20" VerticalAlignment="Center" HorizontalAlignment="Center" />
          <Image Source="/Assets/pause.png" IsVisible="{Binding IsPlaying}" Width="20"
                 Height="20" VerticalAlignment="Center" HorizontalAlignment="Center" />
        </Panel>
      </Button>
    </StackPanel>
  </Grid>
</Window>

error:

  MainWindow.axaml(13, 10): [XAMLIL] Unable to find suitable setter or adder for property Resources of type Avalonia.Styling:Avalonia.StyledElement for argument Avalonia.Visuals:Avalonia.Media.Imaging.Bitmap, available setter parameter lists are:
Avalonia.Controls.IResourceDictionary
System.Collections.Generic.KeyValuePair`2<System.Object,System.Object>
System.Collections.Generic.KeyValuePair`2<TKey,TValue> 第 13 行,位置 10。
Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with applying style on WPF UserControl
When you use an UserControl, it means that you already know its layout, and there is no need to style the control further....
Read more >
GradientStop Class - Typedescriptor
Why am I getting a "Unable to find suitable setter or adder" error when defining a LinearGradientBrush in my <UserControl.Resources>? #3554.
Read more >
LinearGradientBrush Class - Typedescriptor
Why am I getting a "Unable to find suitable setter or adder" error when defining a LinearGradientBrush in my <UserControl.Resources>? #3554.
Read more >
LinearGradientBrush Class (Windows.UI.Xaml.Media)
Paints an area with a linear gradient. ... The XAML syntax shown for Brush types is appropriate for defining the brush as a...
Read more >
the of and to a in for is on s that by this with i you it not
the of and to a in for is on s that by this with i you it not or be are from ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found