Set StaticResource Grid.Column Not Working


  • I have a StackPanel that looks like this:

    <StackPanel x:Name="MyStack" Grid.Row="10" Grid.Column="2" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="0,20,0,0">

    When I go into SnappedView, I'd like this StackPanel to move to Grid.Column 1, and only span 1 column. The code in my VisualStateManager looks like this:

    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Style)" Storyboard.TargetName="MyStack">
      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TEST}"/>

    with the following style declared at the start of the page:

      <CollectionViewSource x:Name="CollectionViewSource" x:Key="CollectionViewSource" />
        <Style x:Key="TEST" TargetType="StackPanel">
          <Setter Property="Grid.Column" Value="1"/>

    However, the StackPanel doesn't switch columns, and since all my other content is already in Column 1, the entire StackPanel is hidden offscreen. How do I get my StackPanel to switch columns/colspans in this way?

    I should mention that I'm trying to switch columns in the StaticResources section because I have several elements I'd like to control in this way, instead of manually specifying for each and every item.

    Thursday, July 5, 2012 7:43 PM


All replies

  • Hello,

    Would you please provide us the whole codes to reproduce this issue,

    You can upload your project to skydriver

    It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it.

    Best regards,

    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 9, 2012 9:05 AM
  • AFAIK this is not a bug. This is expected.

    The solution may be the same as for your other problem, in this other thead http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/317c1719-72c7-4875-945f-22872657cb0d

    Properties set in styles don't overwrite properties which are set in the control, but properties set in a control override properties set in the style.

    If you want a style to modify the property of a control, don't set this property in the control definition.

    The solution is to define two styles, one for standard view, and one for snapped view.
    • Proposed as answer by Pierre Morel-Fourrier Thursday, July 26, 2012 12:38 AM
    • Marked as answer by inspira Wednesday, August 1, 2012 2:14 AM
    Wednesday, July 11, 2012 1:19 AM