相关疑难解决方法(0)

WPF动画"无法冻结此Storyboard时间轴树以跨线程使用"

我目前有一个列表框,其选定的项目绑定到我的ViewModel上的属性.每当所选项目不为null时,我想在其上执行动画.但是,我不断收到以下错误"无法冻结此故事板时间轴树以供跨线程使用",并且从研究中了解为什么会发生这种情况.但是我不确定我需要采取什么方法来获得我想要的行为.

<Storyboard x:Key="ShowItemEdit">
    <DoubleAnimation
        Storyboard.TargetName="lstItemList"
        Storyboard.TargetProperty="ListBox.Width"
        To="{Binding ActualWidth, ElementName=UserControl}"
        Duration="0:0:0.40" />
    ...
</Storyboard>

<Style x:Key="ListStyle">
    <Style.Triggers>
        <DataTrigger Binding="{Binding SelectedItem, Converter={StaticResource IsNullConverter}}" Value="False">
            <DataTrigger.EnterActions>
            <BeginStoryboard Storyboard="{StaticResource ShowItemEdit}" />
        </DataTrigger.EnterActions>
        </DataTrigger>
     </Style.Triggers>
</Style>

<ListBox x:Name="lstItemList" Style={StaticResource ListStyle}" SelectedItem="{Binding SelectedItem}">
    ...
</ListBox>
Run Code Online (Sandbox Code Playgroud)

wpf animation xaml datatrigger mvvm

22
推荐指数
2
解决办法
2万
查看次数

折叠/展开组框

我有以下XAML,其中堆叠了三个组框.在这些组框的标题中是复选框.

我想要实现的目标:当我选中/取消选中一个方框时,我希望相应的组合框能够以平滑的动画慢慢展开/折叠.

我在Blend 4中尝试这个,但我是一个新手.有关如何实现这一目标的任何帮助?特别是,动画可以在XAML中自包含吗?

更新:这似乎接近,但我不太明白

XAML设计师

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="WpfControlLibrary1.MainControl"
    x:Name="MultiVol">
        <StackPanel x:Name="LayoutRoot" HorizontalAlignment="Stretch">
            <GroupBox Margin="8,0" BorderBrush="#FF88B1D8">
                <GroupBox.Header>
                    <WrapPanel>
                    <CheckBox IsChecked="True" VerticalAlignment="Center" />
                    <Label Content="Volatility" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" /> 
                    </WrapPanel>
                </GroupBox.Header>
                <UniformGrid Columns="2">
                    <Label Content="Spots"></Label>
                    <TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
                    <Label Content="Hist. references" />
                    <TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
                    <Label Content="Tenors" />
                    <TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />

                </UniformGrid>
            </GroupBox>
            <GroupBox  Margin="8,0" BorderBrush="#FF88B1D8">
                <GroupBox.Header>
                    <WrapPanel>
                    <CheckBox IsChecked="True" VerticalAlignment="Center" />
                    <Label Content="Skew" Background="#00000000" Foreground="#FF0033FF" …
Run Code Online (Sandbox Code Playgroud)

wpf animation xaml

6
推荐指数
2
解决办法
8551
查看次数

如何获得当前高度为0的WPF UI元素的所需高度?

我的最终目标是在两个UserControl之间设置大小变化的动画.我试图实现这一目标的方式产生了一个主要问题.

我从一个包含一些基本文本和图标显示的DataTemplate开始,一个高度设置为0的'edit'UserControl和一个编辑按钮.编辑UserControl在GridRow中,Height ="Auto",因此它也以高度0开始.按钮具有由按钮单击触发的DoubleAnimation,用于将UserControl的高度设置为0到300.这一切都有效正好.这是一个简化的代码示例.

<DataTemplate x:Key="UserTemplate" DataType="{x:Type dataTypes:User}">
...
<controls:UserView Grid.Row="1" Grid.ColumnSpan="5" x:Name="EditRow" 
    DataContext="{Binding}" Height="0" />
<controls:UserEditor Grid.Row="2" Grid.ColumnSpan="5" x:Name="EditRow" 
    DataContext="{Binding}" Height="0" />
<Button Grid.Row="0" Grid.Column="4" Name="Edit" Style="{StaticResource ButtonStyle}" 
    ToolTip="Edit user" Click="Button_Click">
    <Image Source="/SolutionName;component/Images/Edit.png" Stretch="None" />
    <Button.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Name="EditRowHeightAnimation" 
    Storyboard.TargetName="EditRow" Storyboard.TargetProperty="Height" From="0" 
    To="300" Duration="00:00:0.5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Button.Triggers>
</Button>
...
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)

问题是编辑UserControl不是300像素高,我不知道它在设计时的高度.我尝试了以下,但它不起作用.

<DoubleAnimation Name="EditRowHeightAnimation" Storyboard.TargetName="EditRow"
    Storyboard.TargetProperty="Height" From="0" To="{Binding DesiredSize.Height, 
    ElementName=EditRow}" Duration="00:00:0.5" />
Run Code Online (Sandbox Code Playgroud)

我也尝试从后面的代码编辑UserControl上调用Measure()和UpdateLayout().我注释掉了按钮单击触发器和xaml动画,并在代码后面添加了一个......现在这种方式有效,但我总是得到相同(错误的)DesiredSize.也就是说,UserControl高度会变得动画,但只是到了错误的高度.这是按钮单击处理程序代码.

private void Button_Click(object sender, RoutedEventArgs e)
{
    User currentUser = (User)CollectionViewSource.GetDefaultView(Users).CurrentItem;
    ListBoxItem listBoxItem …
Run Code Online (Sandbox Code Playgroud)

wpf animation user-controls

4
推荐指数
1
解决办法
2942
查看次数

标签 统计

animation ×3

wpf ×3

xaml ×2

datatrigger ×1

mvvm ×1

user-controls ×1