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.

Add Setter Target Property

See original GitHub issue

Is your feature request related to a problem? Please describe. Change the ownership of another element when the selector is activated.

Describe the solution you’d like Considering following Xaml

    <StackPanel>
        <CheckBox x:Name="Choiche1" Content="Quatsion ?"/>
        <TextBox x:Name="Input"/>
        <ComboBox x:Name="List"/>
     </StackPanel>

I’d like to write selector like this:

    <Style Selector="CheckBox#Choiche1[IsChecked=False]">
      <Setter Target="Input" Property="IsEnabale" Value="False"/>
      <Setter Target="List" Property="IsEnabale" Value="True"/>
    </Style>
    <Style Selector="CheckBox#Choiche1[IsChecked=True]">
      <Setter Property="Backgroud" Value="Green"/>
      <Setter Target="Input" Property="IsEnabale" Value="True"/>
      <Setter Target="List" Property="IsEnabale" Value="False"/>
    </Style>

Describe alternatives you’ve considered I know, I can do a similar thing with binding. But the advantage of the proposed solution is to have everything centralized.

Additional context WPF Setter.TargetName UWP Setter.Target

Issue Analytics

  • State:open
  • Created 4 months ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
amwxcommented, May 28, 2023

A long time ago I was also asking if we should add this as a feature.

Nowadays, it feels less useful, especially with 11.0.

I disagree. For the most part, yes, nested styles helped out here a lot but Selectors are still kinda verbose

<Style Selector="^:pointerover">
    <Style Selector="^ /template/ ContentPresenter#ContentPresenter">
        <Setter Property="Foreground" Value="{DynamicResource CheckBoxForegroundUncheckedPointerOver}" />
    </Style>
    <Style Selector="^ /template/ Border#Root">
        <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundUncheckedPointerOver}" />
        <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushUncheckedPointerOver}" />
    </Style>
    <Style Selector="^ /template/ Border#NormalRectangle">
        <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillUncheckedPointerOver}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeUncheckedPointerOver}" />
    </Style>
    <Style Selector="^ /template/ ui|FontIcon#CheckGlyph">
        <Setter Property="Foreground" Value="{DynamicResource CheckBoxCheckGlyphForegroundUncheckedPointerOver}"/>
    </Style>
</Style>

This example from CheckBox could be condensed down to (following UWP’s Target)

<Style Selector="^:pointerover">
    <Setter Target="ContentPresenter.Foreground" Value="{DynamicResource CheckBoxForegroundUncheckedPointerOver}" />
    <Setter Target="Root.Background" Value="{DynamicResource CheckBoxBackgroundUncheckedPointerOver}" />
    <Setter Target="Root.BorderBrush" Value="{DynamicResource CheckBoxBorderBrushUncheckedPointerOver}" />
    <Setter Target="NormalRectangle.Background" Value="{DynamicResource CheckBoxCheckBackgroundFillUncheckedPointerOver}"/>
    <Setter Target="NormalRectangle.BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeUncheckedPointerOver}" />
    <Setter Target="CheckGlyph.Foreground" Value="{DynamicResource CheckBoxCheckGlyphForegroundUncheckedPointerOver}"/>
</Style>
0reactions
jmacatocommented, Jun 27, 2023

Yes I like this solution since it will also simplify setters in styles

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setter.TargetName Property (System.Windows)
You can set this property to the name of any element within the scope of where the setter collection (the collection that this...
Read more >
TargetName property cannot be set on a Style Setter, so ...
Well it turns out that you can't set Storyboard.TargetName in a Style.Setter because it's a style and is abstracted. Hence a reference via ......
Read more >
Getters and Setters: Manage Attributes in Python
Typically, getter methods return the target attribute's value, while setter methods take a new value and assign it to the underlying ...
Read more >
Properties | Kotlin Documentation
You can define custom accessors for a property. If you define a custom getter, it will be called every time you access the...
Read more >
set - JavaScript - MDN Web Docs - Mozilla
In JavaScript, a setter can be used to execute a function whenever a specified property is attempted to be changed. Setters are most...
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