locked
Using DataStateBehavior in a DataGridTemplateColumn.CellTemplate? RRS feed

  • Question

  • I'm using the samples provided in July by the Expression Blend team which includes DataStateBehavior in combination with two VisualStates and a data binding within a DataGridTemplateColumn.CellTemplate.

    The code looks like this:

        <!-- Imagine the rest of the DataGrid definition here -->
        <data:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup>
                            <VisualState x:Name="AddState"/>
                            <VisualState x:Name="EditState">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="AddTextBlock" Storyboard.TargetProperty="(UIElement.Visibility)">
                                        <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Collapsed</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="EditablePanel" Storyboard.TargetProperty="(UIElement.Visibility)">
                                        <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <i:Interaction.Behaviors>
                        <id:DataStateBehavior Binding="{Binding Comment}" Value="{x:Null}" TrueState="AddState" FalseState="EditState"/>
                    </i:Interaction.Behaviors>
    
                    <TextBlock x:Name="AddTextBlock" Text="{Binding Incentives_ListView_Add, Source={StaticResource LocStrings}}" Style="{StaticResource TextLinkStyle}"/>
                    <StackPanel x:Name="EditablePanel" Visibility="Collapsed" Orientation="Horizontal" MouseLeftButtonUp="EditCommentsClicked" Style="{StaticResource EditCommentsPanelStyle}">
                        <Image Source="../../Images/EditIcon.png" Style="{StaticResource CommentsIconStyle}"/>
                        <TextBlock Text="{Binding Incentives_ListView_Edit, Source={StaticResource LocStrings}}" Style="{StaticResource TextLinkStyle}"/>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </data:DataGridTemplateColumn.CellTemplate>

    The problem is that this does nothing - it never toggles state (regardless of which state I put into TrueState and FalseState). Can you see anything wrong with the above?
    • Edited by orangechicken Wednesday, January 20, 2010 10:17 PM Removing <br/> from code
    Wednesday, January 20, 2010 10:16 PM

All replies

  • Hello orangechicken

    the comparison you are making of Valye="{x:Null}" with binding it to comment will never work in this case, as

    Binding
    =
    "
    {Binding Comment}
    "
    

    will never get to know what happenes with it. May be its bcuz the mode=towway is not set or anyother reason. Also the Value must be bound with some Property of any existing control. Just like in my case where i also have two different states Visible and Collapsed, so you have to make some sort of comparison with "Value" say of a textbox's text so here is the sample

    try this

    <ei:DataStateBehavior TrueState="AddState" FalseState="EditState" Value="" Binding="{Binding Text, ElementName="ABCtextbox ", Mode=TwoWay}"/>

    now when the ABCtextbox's value us empty, your addstate will be activated else Edit state will active.

    Or if you can eleborate to what propertychage you want to toggle these states, i will like to help.

    BR,

    -Ali


    k9
    • Proposed as answer by M.Ali.Raza Tuesday, February 1, 2011 3:12 PM
    Tuesday, February 1, 2011 3:11 PM