从窗口引用子用户控件中的网格

2023-12-21

我使用 ItemsControl 将许多用户控件添加到我的主窗口。这工作正常,但我想在将控件添加到 ItemsControl 时添加动画。

我正在使用此线程中的代码:以动画方式插入 ItemsControl https://stackoverflow.com/questions/12654417/animate-insertions-to-itemscontrol

这是我的用户控件

<UserControl>

<UserControl.Resources>
    <converters:CallStatusEnumToBackgroundColor x:Key="CallStatusBackgroundConverter"/>
    <converters:CallStatusEnumToSelectBackgroundColor x:Key="CallStatusToSelectBackgroundConverter"/>

    <Style x:Key="WhiteSegoeText" TargetType="{x:Type TextBlock}">
        <Setter Property="FontFamily" Value="Segoe UI Semibold" />
        <Setter Property="Foreground" Value="{StaticResource AlmostWhite}" />
    </Style>

    <Style x:Key="SelectedColorStyle" TargetType="{x:Type WrapPanel}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="False">
                <Setter Property="Background" Value="{Binding CallStatus, Converter={StaticResource CallStatusBackgroundConverter}}"></Setter>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{Binding CallStatus, Converter={StaticResource CallStatusToSelectBackgroundConverter}}"></Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

</UserControl.Resources>

<UserControl.Background>
    <SolidColorBrush Color="{Binding CallStatus, Converter={StaticResource CallStatusBackgroundConverter}}"/>
</UserControl.Background>

<Grid x:Name="CallGridRoot" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
    <Grid.RenderTransform>
        <TransformGroup>
            <ScaleTransform/>
        </TransformGroup>
    </Grid.RenderTransform>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="45"/>
        <ColumnDefinition Width="45"/>
    </Grid.ColumnDefinitions>
    <TextBlock TextWrapping="Wrap" Text="{Binding CallerName}" Grid.Column="0"
        Style="{DynamicResource WhiteSegoeText}" FontSize="14" VerticalAlignment="Center" Margin="10,0,0,0"/>


    <WrapPanel x:Name="AcceptCallPanel" Visibility="Collapsed" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource SelectedColorStyle}" Margin="0,0,3,0" HorizontalAlignment="Center">
        <Viewbox StretchDirection="DownOnly" Stretch="Uniform" >
            <ContentControl Content="{StaticResource action_call_icon}" HorizontalAlignment="Center" />
        </Viewbox>
    </WrapPanel>

    <WrapPanel x:Name="PausePanel" Visibility="Collapsed" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource SelectedColorStyle}" Margin="0,0,3,0" HorizontalAlignment="Center">
         <Viewbox StretchDirection="DownOnly" Stretch="Uniform" >
              <ContentControl Content="{StaticResource status_pause}" VerticalAlignment="Center" />
         </Viewbox>
    </WrapPanel>

    <WrapPanel x:Name="ResumePanel" Visibility="Collapsed" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource SelectedColorStyle}" Margin="0,0,3,0" HorizontalAlignment="Center">
        <Viewbox StretchDirection="DownOnly" Stretch="Uniform" >
            <ContentControl Content="{StaticResource resume_call}" VerticalAlignment="Center" />
        </Viewbox>
    </WrapPanel>

    <WrapPanel x:Name="ClosePanel" Visibility="Visible" Grid.Column="2" VerticalAlignment="Center" Style="{StaticResource SelectedColorStyle}" Margin="0,0,3,0" HorizontalAlignment="Center">
        <Viewbox StretchDirection="DownOnly" Stretch="Uniform" >
            <ContentControl Content="{StaticResource close_call}" VerticalAlignment="Center" />
        </Viewbox>
    </WrapPanel>
</Grid>

这是主窗口的片段。

<ItemsControl x:Name="CallsForUserContainer" ItemsSource="{Binding callsForUserViewModel.Calls}" Margin="0,10,0,0">
       <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <DataTemplate.Resources>
                        <Storyboard x:Key="ItemAnimation" AutoReverse="False">
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="CallsForUser.CallGridRoot" Storyboard.TargetProperty="(UIElement.Opacity)">
                                <EasingDoubleKeyFrame KeyTime="0" Value="0" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </DataTemplate.Resources>

                    <DataTemplate.Triggers>
                        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                            <BeginStoryboard Storyboard="{StaticResource ItemAnimation}" />
                        </EventTrigger>
                    </DataTemplate.Triggers>

                    <local:CallsForUser/>
                </DataTemplate>
       </ItemsControl.ItemTemplate>
</ItemsControl>

但是当我运行这个时,我的动画出现错误CallsForUser.CallGridRoot没有找到。 如何从动画中的子用户控件引用网格?


您可以尝试并使用流体移动行为 http://msdn.microsoft.com/en-us/library/ff723946%28v=Expression.40%29.aspx instead

您需要添加两个引用:

系统.Windows.交互性

Microsoft.Expression.Interactions

将以下 using 语句添加到您的 xaml 中

    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"

然后,它的使用就很简单:

    <ItemsControl x:Name="CallsForUserContainer" ItemsSource="{Binding callsForUserViewModel.Calls}" Margin="0,10,0,0">
        <i:Interaction.Behaviors>
            <ei:FluidMoveBehavior AppliesTo="Children"/>
        </i:Interaction.Behaviors>

        <!-- Rest of implementation goes here .... -->           

    </ItemsControl>

您还可以为其添加 Ease 功能,使其按照您想要的方式运行。

您可以在以下位置找到更多相关信息:这个帖子 https://stackoverflow.com/questions/12873729/wpf-animate-insertion-into-an-itemscontrol

希望这可以帮助

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从窗口引用子用户控件中的网格 的相关文章

随机推荐

  • 2010 年 .NET Compact Framework 是否更新?

    这个问题 net 紧凑框架 4 0 https stackoverflow com questions 245566 net compact framework 4 0 在VS 2010发布之前就问过这个问题 答案基本上都是说等待发布 现在
  • 请求的资源node.js上不存在Access-Control-Allow-Origin标头[重复]

    这个问题在这里已经有答案了 我在尝试通过 ajax 请求与我的 node js 服务器通信时遇到问题 我已经这样配置我的服务器 var allowCrossDomain function req res next res header Ac
  • 无法从 xml 定义中找到 Activity 中的 onClick 方法

    我试图将一个函数链接到 AndroidStudio 中按钮的 onClick 属性 但由于某种原因 系统无法识别我编码的方法 有趣的是 当我用 Java 编写代码时 它可以正常工作 在 Kotlin 中则不然 我更新了 Kotlin 并检查
  • ul 左侧​​的浮动图像忽略边距/填充

    我有一个段落 后面是一个无序列表 其中有几个列表项 我还有一个图像浮动在其左侧 我遇到的问题是列表项边距 填充与该图像重叠 我希望图像旁边的项目符号按应有的方式缩进 这是一个测试 http testing gorocketfuel com
  • 包含 std::string 的 memset 结构

    我有一个庞大的结构 其中整个内容是标量变量 枚举和标量数组 基于堆栈 但一个 std string 变量除外 现在 这是我的问题 我可以将结构的整个大小设置为 0 就像我会的那样 如果它只是所有标量 或者 std string 在那里是不可
  • 速记类构造函数字段初始化

    我忍不住觉得有一种简写方法可以写成这样 public abstract class MessageBase public String Destination Sender Uid public MessageBase String des
  • 在 F# 中实现受限数字类型的习惯用法/实践?

    假设需要一种数值数据类型 其允许的值落在指定范围内 更具体地说 假设要定义一个最小值为 0 最大值为 5000 的整数类型 这种情况在很多情况下都会出现 例如在对数据库数据类型 XSD 数据类型等进行建模时 在 F 中对此类类型进行建模的最
  • android 在将数据插入数据库之前检查重复值

    String new recorded lastname a lastname record to database Cursor cursor db rawQuery SELECT lastname FROM people null if
  • 如何在 C 中一次清除多个位?

    我如何将所有这些简化为一行 REG BITA REG BITB REG BITC REG BITD REG BITE 您可以使用 按位或 运算符 REG BITA BITB BITC BITD BITE
  • 如何从 Map> 创建 Multimap

    我没有找到这样的多重映射构造 当我想这样做时 我会迭代映射 并填充多重映射 还有其他办法吗 final Map
  • NSOutlineView 组间距

    我正在开发 NSOutlineView SourceList 并希望用我自己的样式替换当前样式 以便更好地查看我的应用程序 我已经使用自定义 NSTableViewRows 更改了默认标题和内容单元格 这很好用 但现在我可以看到组之间有一个
  • 在 WebView 中禁用邮寄地址的自动链接

    android WebView 将自动检测 html 中的邮寄地址 并允许您单击它来启动地图 有没有办法在不更改本机代码的情况下禁用此功能 我可以在 html 标记中添加一些内容或取消 javascript 事件来防止这种情况发生吗 如果我
  • Angular 6 / 在 tsconfig.lib.json 中声明库的路径

    我正在尝试配置路径Angular 6库 我已经成功配置了以前的 Angular 项目的路径 这是我以前的应用程序的工作原理tsconfig json file compilerOptions baseUrl src paths class
  • 变量多态性的初始化

    假设您有以下代码 class A int i 4 A print void print System out println A class B extends A int i 2 this line public static void
  • 更新后的状态值不会在反应函数内部更新

    反应状态更新值显示在使用效果中 但内部函数仅显示旧值 const counter setCounter useState 0 我正在尝试更新设定间隔函数内的计数器值 const handleIncrease gt clearInterval
  • 规范模式对象应该在哪一层“更新”?

    因此 我在这里查看了一些有关规范模式的帖子 但尚未找到此问题的答案 我的问题是 在 n 层架构中 我的规范到底应该在哪里 更新 我可以将它们放在我的服务层 又名 应用程序层 有时被称为 基本上 aspx 代码隐藏会与之对话的东西 中 但我觉
  • 在自定义视图 onDraw 中使用硬件层

    所以我试图了解如何在自定义中正确使用硬件加速 如果可用 View那是持续的动画 这是我的基本前提onDraw canvas drawColor mBackgroundColor for Layer layer mLayers canvas
  • Doctrine2 映射:2 个字段映射到 1 个字段(ManyToOne)

    我有 2 个实体 即比赛和团队 一支球队可以进行一对多的比赛 但是 我的 Match 实体由 2 个字段组成 它们引用同一实体 Team 他们是 homeTeam 和 awayTeam 如何将团队中的同一字段 matches 引用为双向关系
  • Pyinstaller 和 py2exe 导致错误:“元组索引超出范围”

    这是我第一次使用 Pyinstaller 所以请耐心等待 为什么下面的结果会出错呢 我如何解决它 我正在尝试将我编写的python程序转换为windows exe C WINDOWS system32 gt pyinstaller C Us
  • 从窗口引用子用户控件中的网格

    我使用 ItemsControl 将许多用户控件添加到我的主窗口 这工作正常 但我想在将控件添加到 ItemsControl 时添加动画 我正在使用此线程中的代码 以动画方式插入 ItemsControl https stackoverfl