Skip to content

Style selectors not working in custom control. #19053

Closed
@Shadowblitz16

Description

@Shadowblitz16

Describe the bug

I am using a custom control for a preview for my style.
However when I try to use the Button selector to select all buttons and add a padding and corner radius it doesn't update in the designer.

Image

To Reproduce

  • Create a new mvvm avalonia project called SMBX
  • Paste this in Views/MainView.axaml
<Grid 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" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="SMBX.Views.MainView">
    <Grid RowDefinitions="Auto, *, Auto">
        <Menu>
            <MenuItem Header="File">
                <MenuItem Header="New..">
                    <MenuItem Header="Level"/>
                    <MenuItem Header="World"/>
                    <Separator/>
                    <MenuItem Header="Block"/>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Open..">
                    <MenuItem Header="Level"/>
                    <MenuItem Header="World"/>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Save"/>
                <MenuItem Header="Save As..">
                    <MenuItem Header="Level"/>
                    <MenuItem Header="World"/>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Quit"/>
            </MenuItem>
        </Menu>
        <Canvas Grid.Row="1" Background="Black">
            
        </Canvas>
        <StackPanel Grid.Row="2" Orientation="Horizontal">
            <ToggleButton Content="Select"/>
            <ToggleButton Content="Erase"/>
            <Separator/>
            <ToggleButton Content="Blocks"/>
        </StackPanel>
    </Grid>
</Grid>
  • Paste this in Views/MainView.axaml.cs
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace SMBX.Views;

public partial class MainView : Grid
{
    public MainView()
    {
        InitializeComponent();
    }
}
  • Paste this in Styles/Default.axaml
<Styles xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:v="using:SMBX.Views">
    <Design.PreviewWith>
        <v:MainView Width="800" Height="450"/>
    </Design.PreviewWith>

    <!-- Add Styles Here -->
    <Styles>
        <Style Selector="Button">
            <Setter Property="Padding" Value="3"/>
            <Setter Property="CornerRadius" Value="3"/>
        </Style>
    </Styles>
</Styles>

Expected behavior

The Button's in the MainView in the Default style preview should have a padding of 3 and a corner radius of 3.

Avalonia version

11.1.0

OS

Linux

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions