Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5973843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:51:28+00:00 2026-05-22T20:51:28+00:00

Please consider the following piece of code: <Window> <Window.Tag> <Button x:Name=myButton/> </Window.Tag> <Grid> <VisualStateManager.VisualStateGroups>

  • 0

Please consider the following piece of code:

<Window>    
    <Window.Tag>
        <Button x:Name="myButton"/>
    </Window.Tag>

    <Grid>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="VisualState">
                    <Storyboard>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="canvas">
                            <EasingColorKeyFrame KeyTime="0" Value="Red"/>
                        </ColorAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Canvas x:Name="canvas" Background="White">  
            <i:Interaction.Triggers>
                <ei:DataTrigger Value="True">
                    <ei:DataTrigger.Binding>
                        <Binding Path="Equals">
                            <Binding.Source>
                                <local:DependencyObjectComparer X="{x:Reference myButton}" Y="{x:Reference myButton}"/>
                            </Binding.Source>
                        </Binding>
                    </ei:DataTrigger.Binding>
                    <ei:GoToStateAction StateName="VisualState"/>
                </ei:DataTrigger>
                <i:EventTrigger EventName="MouseLeftButtonDown">
                    <ei:GoToStateAction StateName="VisualState"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>          
        </Canvas>
    </Grid>
</Window>

The DependencyObjectComparer does – suprinsingly – compare “X” and “Y” for equality:

public class EqualityComparer<T> : IEqualityComparer<T>
{
    public EqualityComparer(Func<T, T, bool> comparer)
    {
        Contract.Requires(comparer != null);
        this.m_comparer = comparer;
    }

    public bool Equals(T x, T y)
    {
        return this.m_comparer(x, y);
    }

    public int GetHashCode(T obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }

    private readonly Func<T, T, bool> m_comparer;
}

public class LazyEqualityComparer<T> : DependencyObject
{
    static LazyEqualityComparer()
    {
        EqualsProperty = DependencyProperty.Register
        (
            "Equals",
            typeof(bool),
            typeof(LazyEqualityComparer<T>),
            null
        );
    }

    public static readonly DependencyProperty EqualsProperty;

    public Func<T, T, bool> Comparer { get; set; }

    public T X
    {
        get { return this.m_x; }
        set
        {
            if (!object.Equals(this.m_x, value))
            {
                this.m_x = value;
                this.OnComperandChanged();
            }
        }
    }

    public T Y
    {
        get { return this.m_y; }
        set
        {
            if (!object.Equals(this.m_y, value))
            {
                this.m_y = value;
                this.OnComperandChanged();
            }
        }
    }

    [Bindable(true)]
    new public bool Equals
    {
        get { return (bool)this.GetValue(EqualsProperty); }
        private set { this.SetValue(EqualsProperty, value); }
    }

    private void OnComperandChanged()
    {
        this.Equals = new EqualityComparer<T>(
            this.Comparer != null ? this.Comparer : (x, y) => x.Equals(y)
        ).Equals(this.X, this.Y);
    }

    private T m_x;
    private T m_y;
}


public class DependencyObjectComparer : LazyEqualityComparer<DependencyObject> { }

While the EventTrigger is firing when I’m clicking on the Canvas, the DataTrigger is not, while it does return the expected value (true). Is there any incompatibility between this kind of Action and this kind of Trigger?

I’ve no idea what I’m doing wrong here. Thank’s for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:51:29+00:00Added an answer on May 22, 2026 at 8:51 pm

    Finally found a solution by myself:

    <Window>    
        <Window.Tag>
            <Button x:Name="myButton"/>
        </Window.Tag>
    
        <Grid>              
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup>
                    <VisualState x:Name="Default"/>
                    <VisualState x:Name="VisualState">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="canvas">
                                <EasingColorKeyFrame KeyTime="0" Value="Red"/>
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
    
            <Canvas x:Name="canvas" Background="White">         
                <i:Interaction.Triggers>                
                    <ei:PropertyChangedTrigger Binding="{Binding Tag, ElementName=window}">                 
                        <i:Interaction.Behaviors>
                            <ei:ConditionBehavior>
                                <ei:ConditionalExpression>
                                    <ei:ComparisonCondition LeftOperand="{Binding Tag, ElementName=window}" RightOperand="{x:Reference myButton}"/>
                                </ei:ConditionalExpression>
                            </ei:ConditionBehavior>
                        </i:Interaction.Behaviors>
                        <ei:GoToStateAction StateName="VisualState"/>                       
                    </ei:PropertyChangedTrigger>
                    <ei:PropertyChangedTrigger Binding="{Binding Tag, ElementName=window}">                 
                        <i:Interaction.Behaviors>
                            <ei:ConditionBehavior>
                                <ei:ConditionalExpression>
                                    <ei:ComparisonCondition LeftOperand="{Binding Tag, ElementName=window}" RightOperand="{x:Reference myButton}" Operator="NotEqual"/>
                                </ei:ConditionalExpression>
                            </ei:ConditionBehavior>
                        </i:Interaction.Behaviors>
                        <ei:GoToStateAction StateName="Default"/>                       
                    </ei:PropertyChangedTrigger>
                </i:Interaction.Triggers>
            </Canvas>
        </Grid>
    </Window>
    

    Does anybody know if it’s possible to set a False-State without writing the conditions with changed Operator again? Just like that what’s possible with the DataStateBehavior.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following code, <form action=index.php method=post name=adminForm enctype=multipart/form-data> <input type=hidden name=showtime[] id=showtime_1
Please consider the following piece of code: int main() { typedef boost::ptr_vector<int> ptr_vector; ptr_vector
Please consider the following piece of code, which throws three different exceptions (namely, System.Configuration.ConfigurationErrorsException
Please consider following code: 1. uint16 a = 0x0001; if(a < 0x0002) { //
Please consider the following fork() / SIGCHLD pseudo-code. // main program excerpt for (;;)
Please consider the following code: public class Person ( public string FirstName {get; set;}
Please consider the following code, struct foo { foo() { std::cout << Constructing! <<
Please consider the following code: class Abase{}; class A1:public Abase{}; class A2:public A1{}; //etc
please consider the following code: template <typename T> struct foo { template <typename S>
Please consider the following code and the explanation from this Mozilla tutorial Using web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.