Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight-如何在a<;ListBox.ItemTemplate>;_Silverlight_Xaml - Fatal编程技术网

Silverlight-如何在a<;ListBox.ItemTemplate>;

Silverlight-如何在a<;ListBox.ItemTemplate>;,silverlight,xaml,Silverlight,Xaml,我试图在一个窗口中显示绑定数据的列表,然后在每行后面设置画布动画。当我把故事板放在模板中时,我很难让它开始。以下是我到目前为止使用的XAML的一个示例: <ListBox x:Name="MyListBox" Background="Transparent" Foreground="White" Height="200" Width="400" BorderThickness="0" Margin="0"> <ListBox.ItemTemplate&g

我试图在一个窗口中显示绑定数据的列表,然后在每行后面设置画布动画。当我把故事板放在模板中时,我很难让它开始。以下是我到目前为止使用的XAML的一个示例:

    <ListBox x:Name="MyListBox" Background="Transparent" Foreground="White" Height="200" Width="400" BorderThickness="0" Margin="0">
        <ListBox.ItemTemplate>
            <DataTemplate x:Name="MySingleDataTemplate">
                <StackPanel Orientation="Horizontal" x:Name="MySingleStackPanel" Margin="0">
                    <StackPanel.Resources>
                        <Storyboard x:Name="MySingleStoryboard" BeginTime="0:0:1">
                            <DoubleAnimationUsingKeyFrames  Storyboard.TargetName="Canvas99" Storyboard.TargetProperty="Width" 
                                            AutoReverse="True" RepeatBehavior="Forever">
                                <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
                                <LinearDoubleKeyFrame Value="400" KeyTime="0:0:3" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </StackPanel.Resources>
                    <Grid Background="Black" x:Name="MySingleGrid" Margin="0" ShowGridLines="False">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="Col0" Width="300" />
                            <ColumnDefinition x:Name="Col1" Width="100" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30" x:Name="Row0" />
                        </Grid.RowDefinitions>
                        <Canvas Background="{Binding CanvasColour}" Grid.Row="0" Grid.Column="0" x:Name="Canvas99" HorizontalAlignment="Left" />
                        <TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding Field1}" Margin="0"/>
                        <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Field2}" Margin="0"/>
                    </Grid>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
是否有一种方法可以让它从C#开始,或者是否有一些其他属性或触发器可以在Silverlight中使用?还是我完全走错了路

谢谢
迈克设法回答了我自己的问题!我需要添加到StackPanel,如下所示:

                    <StackPanel.Triggers>
                        <EventTrigger RoutedEvent="StackPanel.Loaded">
                            <EventTrigger.Actions>
                                <BeginStoryboard>
                                    <Storyboard x:Name="MySingleStoryboard" BeginTime="0:0:1">
                                        <DoubleAnimationUsingKeyFrames  Storyboard.TargetName="Canvas99" Storyboard.TargetProperty="Width" 
                                            AutoReverse="True" RepeatBehavior="Forever">
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
                                            <LinearDoubleKeyFrame Value="400" KeyTime="0:0:3" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger.Actions>
                        </EventTrigger>
                    </StackPanel.Triggers>

工作是一种享受,现在我只需要去掉列表框上的所有边距/寄宿生等,我会很高兴的。。。。现在。 迈克

                    <StackPanel.Triggers>
                        <EventTrigger RoutedEvent="StackPanel.Loaded">
                            <EventTrigger.Actions>
                                <BeginStoryboard>
                                    <Storyboard x:Name="MySingleStoryboard" BeginTime="0:0:1">
                                        <DoubleAnimationUsingKeyFrames  Storyboard.TargetName="Canvas99" Storyboard.TargetProperty="Width" 
                                            AutoReverse="True" RepeatBehavior="Forever">
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
                                            <LinearDoubleKeyFrame Value="400" KeyTime="0:0:3" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger.Actions>
                        </EventTrigger>
                    </StackPanel.Triggers>