Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style Without Trigger, need HELP #3789

Closed
Rukid opened this issue Apr 16, 2020 · 4 comments
Closed

Style Without Trigger, need HELP #3789

Rukid opened this issue Apr 16, 2020 · 4 comments

Comments

@Rukid
Copy link

Rukid commented Apr 16, 2020

Hello, in wpf i have style for checkbox

<Style x:Key="LEDCheckBox" TargetType="CheckBox">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="IsEnabled" Value="False"/>
        <Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="CheckBox">
                    <Ellipse x:Name="Border" 
                          Width="{TemplateBinding Width}" 
                          Height="{TemplateBinding Height}" 
                          Stroke="Gray" StrokeThickness="1">
                    </Ellipse>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="Border" Property="Fill" Value="#7FFFD4"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="False">
                            <Setter TargetName="Border" Property="Fill" Value="#F9B5B5"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

How to use it in avalonia without trigger and converters?

@danwalmsley
Copy link
Member

<Style x:Key="LEDCheckBox" TargetType="CheckBox"> can be:
<Style Selector="CheckBox">

@danwalmsley
Copy link
Member

<Style Selector="CheckBox:checked"> </Style>

To target the control when its checked...

@danwalmsley
Copy link
Member

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Default/CheckBox.xaml

if you want to replace the checkbox template,,, start with the default one here.

@Rukid
Copy link
Author

Rukid commented Apr 16, 2020

Thank's alot. If someone interested i changed my code to:

<Style Selector="CheckBox">
   <Setter Property="IsEnabled" Value="False"/>
   <Setter Property="Template">
     <ControlTemplate>
       <Ellipse x:Name="border"
                Width="{TemplateBinding Width}"
                Height="{TemplateBinding Height}"
                Stroke="Gray" StrokeThickness="1">
       </Ellipse>
     </ControlTemplate>
   </Setter>
 </Style>

 <Style Selector="CheckBox:checked /template/ Ellipse#border">
   <Setter Property="Fill" Value="#7FFFD4"></Setter>
 </Style>

 <Style Selector="CheckBox:unchecked /template/ Ellipse#border">
   <Setter Property="Fill" Value="#F9B5B5"></Setter>
 </Style>

@maxkatz6 maxkatz6 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants