0

I'm trying to create a to do list in Windows 8 XAML. when I complete an item, I want a storyboard to erase the completed items. How can I get a storyboard to run on items inside a datatemplate? when I run the storyboard from C#, I get an error that says: WinRT information: Cannot resolve TargetName rectangleToDelete.

My storyboard looks like this:

<Page.Resources>
    <Storyboard x:Name="AnimateDelete">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="rectangleToDelete">
            <EasingDoubleKeyFrame KeyTime="0" Value="-0.333"/>
            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="-327.5"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="rectangleToDelete">
            <EasingDoubleKeyFrame KeyTime="0" Value="0.333"/>
            <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="-163.25"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</Page.Resources>

My Listview template looks like this:

<ListView.ItemTemplate>
  <DataTemplate>

    <Grid>
      <StackPanel Orientation="Horizontal"
                  Margin="0,0,-393,-15">
        <CheckBox x:Name="CheckBoxComplete"
                  IsChecked="{Binding Complete, Mode=TwoWay}"
                  Checked="CheckBoxComplete_Checked"
                  Content="{Binding Text}"
                  Margin="10,5"
                  VerticalAlignment="Center"
                  MinWidth="300" />
        <Button x:Name="ButtonDelete"
                Click="ButtonDelete_Click"
                Content="Delete" />
      </StackPanel>
      <Rectangle x:Name="rectangle"
                 Fill="#FFF4F4F5"
                 Stroke="Black"
                 StrokeThickness="0"
                 RenderTransformOrigin="0.5,0.5"
                 Margin="319,2,-300,-14"
                 Height="34"
                 VerticalAlignment="Top">
        <Rectangle.RenderTransform>
          <CompositeTransform ScaleX="-1" />
        </Rectangle.RenderTransform>
      </Rectangle>
    </Grid>
  </DataTemplate>
</ListView.ItemTemplate>

My codebehind looks like this:

        Button btn = (Button)sender;
        TodoItem item = btn.DataContext as TodoItem;

        StackPanel stk = (StackPanel)btn.Parent;
        Grid grd = (Grid)stk.Parent;
        Rectangle rect = (Rectangle)grd.Children[1];
        rect.Name = "rectangleToDelete";
        AnimateDelete.Begin();

as you can see, I've tried finding the rectangle and giving it the correct name, but I get the same error.

any help would be appreciated!

thanks, tom

1 Answer 1

2

A DataTemplate has a different namescope than anything outside. You can put the contents of that DataTemplate and the Storyboard in their own UserControl to get it to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.