How can I apply a conditional effect to a button based on value in the ViewModel?

Digital Camel

I can easily add a little glow effect to a button using something like this:

<Button ...>
  <Button.Effect>
    <DropShadowEffect ... />
  </Button.Effect>
</Button>

How can I apply the effect conditionally, based on a value in the ViewModel?

Basically I want the button to "glow" if a new document has been added in the last few days. I can supply the bool value indicating if the glow is required as a property of the ViewModel.

I was thinking of just creating two buttons attached to the same command, hiding one and showing the other based on the ViewModel. That would work, but it seems a bit brute forced.

Thoughts?

Thanks.

J

M.E.

You need to create a style for your Button with a DataTrigger like this:

<Button Content="Hello" Command="{Binding HelloCommand}">
    <Button.Style>
        <Style TargetType="Button">
            <Style.Triggers>
                <DataTrigger Binding="{Binding SomeCondition}" Value="True">
                    <Setter Property="Effect">
                        <Setter.Value>
                            <DropShadowEffect />
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>

Note that SomeCondition is a boolean property in your view model. Only when SomeCondition is true, the effect gets applied.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how can i add button to this code to apply this effect on my image i am making an image editor app

From Dev

How can I apply a fadein effect to a function?

From Dev

How to apply Conditional Formatting based on previous cell value?

From Dev

How can I apply brightness effect only to the part of a image?

From Dev

How can I apply a graphic effect to the image in QListView?

From Dev

How can I apply a graphic effect to the image in QListView?

From Dev

How can I apply brightness effect only to the part of a image?

From Dev

How can i apply this blur effect on my website

From Dev

How can I check for a value in a conditional array?

From Dev

How I can give the effect of a button to an ImageView when I click?

From Dev

How Can I Apply Conditional Decorator to a Command Handler with SimpleInjector?

From Dev

How can i bind a button in listviewitem to a Command in ViewModel in Winrt

From Dev

How can I disable an HTML button based on value stored in PHP array?

From Dev

Can I apply conditional inputting on Excel?

From Dev

How can I show the visual effect of a pressed button when I press another button?

From Dev

How can I change the value of a submit button

From Dev

How can I change button value with stylish?

From Dev

How Can I Apply Different Formats Based on Data Values

From Dev

How can I apply style to a div based on condition in thymeleaf?

From Dev

how can I apply css based on parent div class

From Dev

How Can I Apply Different Formats Based on Data Values

From Dev

How can I apply differnt styles when transforming data using json2html based on data value?

From Dev

How can I set a conditional function argument value here?

From Dev

How can I apply a fade-out-text effect with a transparent-to-white gradient?

From Dev

How can I do the slide down effect to not bring my web page back to top when I press the button that actions the effect?

From Dev

How can I do the slide down effect to not bring my web page back to top when I press the button that actions the effect?

From Dev

How can I apply groupBy but use a different value as my key?

From Dev

How can I apply translate() to an attribute value in XSLT?

From Dev

How can I apply numberSuffix on value only for fusionchart gauge chart

Related Related

  1. 1

    how can i add button to this code to apply this effect on my image i am making an image editor app

  2. 2

    How can I apply a fadein effect to a function?

  3. 3

    How to apply Conditional Formatting based on previous cell value?

  4. 4

    How can I apply brightness effect only to the part of a image?

  5. 5

    How can I apply a graphic effect to the image in QListView?

  6. 6

    How can I apply a graphic effect to the image in QListView?

  7. 7

    How can I apply brightness effect only to the part of a image?

  8. 8

    How can i apply this blur effect on my website

  9. 9

    How can I check for a value in a conditional array?

  10. 10

    How I can give the effect of a button to an ImageView when I click?

  11. 11

    How Can I Apply Conditional Decorator to a Command Handler with SimpleInjector?

  12. 12

    How can i bind a button in listviewitem to a Command in ViewModel in Winrt

  13. 13

    How can I disable an HTML button based on value stored in PHP array?

  14. 14

    Can I apply conditional inputting on Excel?

  15. 15

    How can I show the visual effect of a pressed button when I press another button?

  16. 16

    How can I change the value of a submit button

  17. 17

    How can I change button value with stylish?

  18. 18

    How Can I Apply Different Formats Based on Data Values

  19. 19

    How can I apply style to a div based on condition in thymeleaf?

  20. 20

    how can I apply css based on parent div class

  21. 21

    How Can I Apply Different Formats Based on Data Values

  22. 22

    How can I apply differnt styles when transforming data using json2html based on data value?

  23. 23

    How can I set a conditional function argument value here?

  24. 24

    How can I apply a fade-out-text effect with a transparent-to-white gradient?

  25. 25

    How can I do the slide down effect to not bring my web page back to top when I press the button that actions the effect?

  26. 26

    How can I do the slide down effect to not bring my web page back to top when I press the button that actions the effect?

  27. 27

    How can I apply groupBy but use a different value as my key?

  28. 28

    How can I apply translate() to an attribute value in XSLT?

  29. 29

    How can I apply numberSuffix on value only for fusionchart gauge chart

HotTag

Archive