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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:06:31+00:00 2026-06-14T17:06:31+00:00

I have some controls in a DataTemplate and I’d like to control it’s pressed

  • 0

I have some controls in a DataTemplate and I’d like to control it’s pressed state behaviour. I did the following where I just put in VisualStateManager in the DataTemplate but it doesn’t seem to work. I think it’s possible to understand what I’m trying to do below. Is it possible to do it inline inside the DataTemplate tags?

<ItemsControl ItemsSource="{Binding Items}">
    ....
    <ItemsControl.ItemTemplate>
        <DataTemplate>
          <Grid ...>
             <VisualStateManager.VisualStateGroups>
                 <VisualStateGroup x:Name="CommonStates">
                     ...
                     <VisualState x:Name="Pressed">
                         <Storyboard>
                             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderThickness" Storyboard.TargetName="GridItemBorder">
                                 <DiscreteObjectKeyFrame KeyTime="0" Value="3"/>
                              </ObjectAnimationUsingKeyFrames>
                         </Storyboard>
                     </VisualState>
                 </VisualStateGroup>
             </VisualStateManager.VisualStateGroups>
             <Border x:Name="Border" ...>
                 ...
             </Border>
          </Grid>
      </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl>
  • 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-06-14T17:06:32+00:00Added an answer on June 14, 2026 at 5:06 pm

    The short answer is that there is no “Pressed” visual state for the control type you’re targeting — so while you can reference any state in the Visual State Manager, it won’t matter, because the control’s code will never put it into that state.

    You can see which visual states a control supports by looking at its definition (they’re declared using the TemplateVisualState attribute), or by looking at this section on MSDN.

    The way to go here might be to use the Button (or an override of [ButtonBase][2] that you write), since that has the “Pressed” visual state built in. You’d just have to write a Control Template for it that provides the layouts/styles that you’re after.


    Edit Here’s an example:

    Control template (resources section). This is a control template for the Button control, but it’s not really a button. I’m just using it to take advantage of the “Pressed” visual state functionality.

        <ControlTemplate x:Key="MyButtonTemplate" TargetType="Button">
            <Grid>
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Pressed">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" Storyboard.TargetName="GridItemBorder">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="3"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Border x:Name="GridItemBorder" BorderBrush="Orange" BorderThickness="1" Background="White">
                    <ContentPresenter Content="{TemplateBinding Content}" />
                </Border>
            </Grid>
        </ControlTemplate>
    

    Items control

    Define the item template as a “Button” which uses the above ControlTemplate.

        <ItemsControl ItemsSource="{Binding SelectedItems}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Template="{StaticResource MyButtonTemplate}" Content="{Binding}" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET page using the AJAX control toolkit for some controls. A
I have a FlipView with some controls in the DataTemplate. Since it's in a
I have a grid with some controls inside. I want to hide the grid
I have a page with some controls, usercontrols etc. when I change a div
I have a form with some controls. (Actually, this is a sort of ongoing
I have an MVC page, with some controls inside a form. The part I
I have a UpdatePanel with a PlaceHold contained in it. I create some controls
I have a form and a sub-form, both with some controls that are bound
For some user controls, I have this binding: AppLanguage={Binding Path=ApplicationLanguage, Source={x:Static Application.Current}} This works
I have a page (telerik:RadPage) containing few grids and some nested controls and I

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.