我一直对一些我认为是Angular 4动画模块中的错误感到困惑.通过Angular 2.x中的动画,我制作了一个动画,从高度*动画到固定高度.这在Angular 2中运行得非常好.另一方面,当使用Angular 4时,在动画完成之前重新触发动画时,应用动画的元素的高度会出错.通配符(*)高度似乎是导致问题的原因.这是一个可以重现问题的演示片段.如果在元素处于*-height状态时双击该元素,则可以触发该错误:
import { Component } from '@angular/core';
import { trigger, animate, state, transition, style } from '@angular/animations';
@Component({
selector: 'app-root',
template: `
<h1 [@toggleAnimation]="isEnabled" (click)="isEnabled = isEnabled === 'active' ? 'inactive' : 'active'" style="background: blue">
{{title}}
</h1>`,
animations:
[
trigger('toggleAnimation', [
state('active', style({
height: '*',
})),
state('inactive', style({
height: '600px',
})),
transition('active <=> inactive', animate('500ms ease-in-out'))
])
]
})
export class AppComponent {
title = 'app works!';
isEnabled = 'inactive';
}
Run Code Online (Sandbox Code Playgroud)
如何使用通配符值为高度设置动画有什么问题,或者通配符高度的表现方式是否有问题?
我目前正在开发一个项目,我使用Caliburn在View和ViewModel之间进行绑定.为了能够在运行时在语言之间切换,我有单独的资源文件,其中包含应用程序中使用的所有字符串.一些例如TextBlock文本绑定绑定到其中一个字符串资源,如下所示:
SampleView.xaml
<TextBlock Text={DynamicResource Foo.Bar.Baz} ... />
Language.en-US.xaml
<system:String x:Key="Foo.Bar.Baz">Im a string</system:String>
当我将应用程序的文化更改为其他语言时,对Foo.Bar.Baz 的动态绑定使字符串在运行时更新为新语言.大!
但是,应用程序中的某些Text属性绑定到带有Caliburn的ViewModel中的字符串,如下所示:
SampleView.xaml
<TextBlock Text={Binding SampleText} ... />
SampleViewModel.cs
public string SampleText { get; set; }
值的值SampleText设置为Language.en-US.xaml中的字符串资源,如下所示:
...
SampleText = Application.Current.FindResource("Foo.Bar.Baz") as string;
...
不幸的是,当我更改应用程序文化时,字符串SampleText不会更新.
问题是: 如何将SampleText设置为Language.en-US.xaml中的字符串资源,当我更改应用程序文化时,它将自动更新?
注意:通过对此StackOverflow问题的评论,我读到可以通过类似的bindnig:
SampleText = Application.Current.Resource["Foo.Bar.Baz"] as string;
但是,这对我不起作用.