当绑定的属性“快速”更改时,我无法使用 DataTriggers 在 WPF 中制作动画。动画是一个元素的简单闪烁。我的问题是,即使在互联网上搜索了很长时间后,我也无法找到一种方法来解释为什么在连续两行中切换属性打开和关闭不起作用,但如果线程休眠 1 毫秒,它就会起作用。我尝试插入其他指令来“浪费”一些时间,但它也不起作用。
这是视图模型中相关的属性:
private bool m_activateFlash;
public bool ActivateFlash
{
get { return m_activateFlash; }
set
{
SetPropertyBackingField(ref m_activateFlash, value);
}
}
Run Code Online (Sandbox Code Playgroud)
这是 XAML:
<DataTemplate x:Key="JobTemplate" DataType="viewModel:JobViewModel">
<Border Margin="8,4,8,4" BorderThickness="1" BorderBrush="{StaticResource BorderBrush}" Background="{StaticResource JobBackgroundBrush}">
<Border.Resources>
<Storyboard x:Key="Blink">
<ColorAnimation Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" FillBehavior="Stop"
Duration="0:0:0.4" To="{StaticResource JobBackgroundFlash}" RepeatBehavior="3x" AutoReverse="True"/>
</Storyboard>
</Border.Resources>
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding ActivateFlash, NotifyOnTargetUpdated=True}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource Blink}" Name="BeginBlinkStoryBoard"/>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
[....]
Run Code Online (Sandbox Code Playgroud)
最后,这就是它在视图模型中给我带来问题的地方:
private void TriggerFlash()
{
ActivateFlash = true; …Run Code Online (Sandbox Code Playgroud) 我的一个微服务 Web api 遇到了一个奇怪的问题。我的异步 GET 方法会抛出无法访问 DbContext 的已处置对象异常,除非第一次调用它们。我尝试在网上寻找答案,但没有任何效果。我确保我的方法不是 async void,并且我等待必要的调用。由于我的 POST 和 DELETE 方法工作正常,我相当确定真正的罪魁祸首是 IMapper 实例。我认为它可能总是指向 DbContext 的第一个实例,这就是为什么第一次可以工作但之后就不行的原因。任何帮助或指示将不胜感激
这是代码的一些快照。
启动.cs
...
// Add AutoMapper
services.AddAutoMapper(new Assembly[] { typeof(AutoMapperProfile).GetTypeInfo().Assembly });
// Add DbContext using NoSQL Server Provider
services.AddDbContext<ProfileDbContext>(options =>
options.UseMongoDb(Configuration.GetConnectionString("TeamJobProfilesDatabase")));
...
Run Code Online (Sandbox Code Playgroud)
MyController.cs
// GET api/profiles
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<ProfilesListViewModel>> GetAll()
{
return Ok(await Mediator.Send(new GetAllProfilesQuery()));
}
// GET api/profiles/{id}
[HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<ProfileViewModel>> Get(int id)
{
return Ok(await Mediator.Send(new GetProfileQuery { Id = id }));
} …Run Code Online (Sandbox Code Playgroud) c# async-await entity-framework-core .net-core asp.net-core-webapi