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 7509741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:00:39+00:00 2026-05-29T23:00:39+00:00

How to change the visual behavior dynamically through VisualStateManager without changing visual structure (Appearance)

  • 0

How to change the visual behavior dynamically through VisualStateManager without changing visual structure (Appearance) of an existing control.

I have a scenario where i have a DataTemplate defined in ItemsControl to generate list of CheckBoxes and associated TextBoxes.

XAML:

<DataTemplate>
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="0.2*" />
      <ColumnDefinition Width="0.8*" />
    </Grid.ColumnDefinitions>                        
    <CheckBox Grid.Column="0" x:Name="chkBox" />
    <TextBox Grid.Column="1" x:Name="txtBox" />
  </Grid>
</DataTemplate>

I wanted to hide associated TextBoxes initially but later when CheckBox is Checked the associated TextBox should appear. So i wrote VisualStateManager but i don’t have exact idea how can i use it or achieve the desired behavior.

VisualStateManager:

<vsm:VisualStateManager.VisualStateGroups>
  <vsm:VisualStateGroup x:Name="CheckStates">
    <vsm:VisualState x:Name="Checked">
      <Storyboard>
        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="txtBox" Storyboard.TargetProperty="Visibility">
          <DiscreteObjectKeyFrame KeyTime="0">
            <DiscreteObjectKeyFrame.Value>
              <vsm:Visibility>Collapsed</vsm:Visibility>
            </DiscreteObjectKeyFrame.Value>
          </DiscreteObjectKeyFrame>
         </ObjectAnimationUsingKeyFrames>
      </Storyboard>
      </vsm:VisualState>
      <vsm:VisualState x:Name="Unchecked">
        <Storyboard>
          <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="txtBox" Storyboard.TargetProperty="Visibility">
          <DiscreteObjectKeyFrame KeyTime="0">
            <DiscreteObjectKeyFrame.Value>
              <vsm:Visibility>Visible</vsm:Visibility>
            </DiscreteObjectKeyFrame.Value>
          </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
      </Storyboard>
    </vsm:VisualState>
  </vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
  • 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-29T23:00:41+00:00Added an answer on May 29, 2026 at 11:00 pm

    I don’t know if you can target another control’s properties with Visual States – it may be possible, but I’m not sure if you can.

    Have you tried using Interactivity?

    For this to work you need a reference to the System.Windows.Interactivity DLL (not sure where that is located – it might come with Microsoft Expression Blend/Studio). You also need to import these:

    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"             
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    

    And then this code should work to show the textbox:

    <CheckBox Grid.Column="0" x:Name="chkBox">
      <i:Interaction.Triggers>
        <i:EventTrigger EventName="Checked">
           <ei:ChangePropertyAction TargetObject="{Binding ElementName=txtBox}" PropertyName="Visibility" Value="Visible"/>
       </i:EventTrigger>
     </i:Interaction.Triggers>
    </Checkbox>
    

    and to change it back:

    <i:EventTrigger EventName="UnChecked">
       <ei:ChangePropertyAction TargetObject="{Binding ElementName=txtBox}" PropertyName="Visibility" Value="Collapsed"/>
    </i:EventTrigger>
    

    Both triggers should be inside the checkbox < checkbox >HERE< /checkbox >. This code is not tested, so it may not be exactly correct. If it doesn’t work, just search on ChangePropertyAction and you’ll find better examples than this one. I’m not sure how this will react inside of an itemscontrol… but I believe it will work.

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

Sidebar

Related Questions

I'm trying to change a namespace in Visual Studio. My folder structure looks something
I use Microsoft Visual SourceSafe for version control. I would like to change this
Using Silverlight 4. I have two visual states for my control. I want to
I am experiencing some annoying behavior with Visual Studio .NET 2008. We have created
Is there a way in visual studio to change the behavior when I double
How can I change default Generate Method Stub behavior in Visaul Studio to generate
I would like to change visual studio's default configurations (Debug,Release). That is, change the
Is there any way to change Visual Studio Auto formatting options? Like VS by
C#3 (Visual Studio 2008) introduced a breaking change to the language ( http://msdn.microsoft.com/en-us/library/cc713578.aspx ,
Is there a way to change the context sensitive help in Visual Studio so

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.