ListBox ItemTemplate 上的状态动画

发布于 2024-09-02 04:50:23 字数 1445 浏览 3 评论 0原文

我有一个从 Observable 集合中读取的列表框,并且是 ItemTemplate'ed:

<DataTemplate x:Key="DataTemplate1">
    <Grid x:Name="grid" Height="47.333" Width="577" Opacity="0.495">
        <Image HorizontalAlignment="Left" Margin="10.668,8,0,8" Width="34" Source="{Binding ImageLocation}"/>
        <TextBlock Margin="56,8,172.334,8" TextWrapping="Wrap" Text="{Binding ApplicationName}" FontSize="21.333"/>
        <Grid x:Name="grid1" HorizontalAlignment="Right" Margin="0,10.003,-0.009,11.33" Width="26" Opacity="0" RenderTransformOrigin="0.5,0.5">
            <Image HorizontalAlignment="Stretch" Margin="0" Source="image/downloads.png" Stretch="Fill" MouseDown="Image_MouseDown" />
        </Grid>
    </Grid>
</DataTemplate>

<ListBox x:Name="searchlist" Margin="8" ItemTemplate="{DynamicResource DataTemplate1}" ItemsSource="{Binding SearchResults}" SelectionChanged="searchlist_SelectionChanged" ItemContainerStyle="{DynamicResource ListBoxItemStyle1}" />

一般来说,我的问题是“在选择此列表框中的特定项目时,最简单的方法是什么?基本上是“grid1”内的图像将其不透明度设置为 1,慢慢地,

我更喜欢使用状态,但我不知道有什么方法可以告诉 Blend 和 xaml“当选定的项目更改时,在一段时间内将图像不透明度更改为 1”。 .3秒”。事实上,我一直在使用VisualStateManager在.cs文件中执行此操作。

此外,还有另一个问题。当选定的索引更改时,我们转到CS文件并查看SelectedItem。SelectedItem返回一个实例它绑定到的对象(可观察集合内的对象),而不是 DataTemplate/ListItem 等的实例。那么我如何使用

VisualStateManager 处理该列表中的正确图像呢?如果这只是正常的事情,那很好,但是当涉及到生成的列表框的项目时,我迷失了。

谢谢

I have a listbox which reads from Observable collection, and is ItemTemplate'ed:

<DataTemplate x:Key="DataTemplate1">
    <Grid x:Name="grid" Height="47.333" Width="577" Opacity="0.495">
        <Image HorizontalAlignment="Left" Margin="10.668,8,0,8" Width="34" Source="{Binding ImageLocation}"/>
        <TextBlock Margin="56,8,172.334,8" TextWrapping="Wrap" Text="{Binding ApplicationName}" FontSize="21.333"/>
        <Grid x:Name="grid1" HorizontalAlignment="Right" Margin="0,10.003,-0.009,11.33" Width="26" Opacity="0" RenderTransformOrigin="0.5,0.5">
            <Image HorizontalAlignment="Stretch" Margin="0" Source="image/downloads.png" Stretch="Fill" MouseDown="Image_MouseDown" />
        </Grid>
    </Grid>
</DataTemplate>

<ListBox x:Name="searchlist" Margin="8" ItemTemplate="{DynamicResource DataTemplate1}" ItemsSource="{Binding SearchResults}" SelectionChanged="searchlist_SelectionChanged" ItemContainerStyle="{DynamicResource ListBoxItemStyle1}" />

In general, my question is "What is the easiest way to do Animation on Particular Items in this listbox As they are selected? Basically the image inside the "grid1" will be setting its opacity to 1, slowly.

I would prefer to use states, but I do not know of any way to just tell blend and xaml to "When a selected item is changed, change the image opacity to 1 over a period of .3 seconds". Infact, I have been doing this in the .cs file using the VisualStateManager.

Also, there is another issue. When the selected index is changed, we goto the CS file and look at SelectedItem. SelectedItem returns an instance of the Object in which it was bound to (The object inside the observable collection), and NOT an instance of the DataTemplate/ListItem etc. So how am I able to pull the correct image out of this list?

State animation with VisualStateManager I can handle fine if its just normal things, but when it comes to generated listboxes' items, I'm lost.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

握住你手 2024-09-09 04:50:23

这可以通过另一篇文章来回答:
WPF/Silverlight 状态 - 从 XAML 激活?

特别感谢:Dan Auclair

This can be answered via this other post:
WPF/Silverlight States - Activate from XAML?

Special Thanks to: Dan Auclair

半寸时光 2024-09-09 04:50:23

我通过使用堆栈面板中的故事板而不是网格来在列表框项目模板中声明动画。

<StackPanel Grid.Row="0" Height="175" Orientation="Vertical" Width="Auto">

  <StackPanel.Triggers>
    <EventTrigger RoutedEvent="StackPanel.Loaded">
      <EventTrigger.Actions>
        <BeginStoryboard>
          <Storyboard x:Name="mystoryboard">

            <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="Trans"
            Storyboard.TargetProperty="X">
              <LinearDoubleKeyFrame Value="-387" KeyTime="0:0:1" />
            </DoubleAnimationUsingKeyFrames>
          </Storyboard>

        </BeginStoryboard>
      </EventTrigger.Actions>
    </EventTrigger>
  </StackPanel.Triggers>

  <TextBlock Margin="400,40,-400,0" TextWrapping="Wrap" Text="{Binding ApplicationName}" FontSize="21.333">
    <TextBlock.RenderTransform>
      <TranslateTransform x:Name="Trans" X="0" Y="0" />
    </TextBlock.RenderTransform>
  </TextBlock>
</StackPanel>

如果你想在网格中使用它,你不需要提供触发函数。它将文本块从右向左移动。请尝试举办活动来激活此功能。

I have stated animation in the listbox item templates by using the story board in the stack panel instead if grid.

<StackPanel Grid.Row="0" Height="175" Orientation="Vertical" Width="Auto">

  <StackPanel.Triggers>
    <EventTrigger RoutedEvent="StackPanel.Loaded">
      <EventTrigger.Actions>
        <BeginStoryboard>
          <Storyboard x:Name="mystoryboard">

            <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="Trans"
            Storyboard.TargetProperty="X">
              <LinearDoubleKeyFrame Value="-387" KeyTime="0:0:1" />
            </DoubleAnimationUsingKeyFrames>
          </Storyboard>

        </BeginStoryboard>
      </EventTrigger.Actions>
    </EventTrigger>
  </StackPanel.Triggers>

  <TextBlock Margin="400,40,-400,0" TextWrapping="Wrap" Text="{Binding ApplicationName}" FontSize="21.333">
    <TextBlock.RenderTransform>
      <TranslateTransform x:Name="Trans" X="0" Y="0" />
    </TextBlock.RenderTransform>
  </TextBlock>
</StackPanel>

If you want to use it in grid you dont need to give the trigger functions. It moves the textblock from right to left. Kindly try to have an event to activate this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文