简体   繁体   English

WPF LayoutChanged不会触发笔刷更改...什么事件发生?

[英]WPF LayoutChanged won't fire for brush change… what event does?

I have an application where I am using WPF to live-render an MVVM-based Control to an external LCD panel. 我有一个应用程序,使用WPF将基于MVVM的控件实时渲染到外部LCD面板。 I'm propagating each frame using RenderBitmapTarget in a rendering loop and then handing off the byte buffer. 我正在渲染循环中使用RenderBitmapTarget传播每个帧,然后移交字节缓冲区。 The way I know I need to make a render call as opposed to sitting idle is by setting a flag in the LayoutUpdated handler. 我知道我需要进行渲染调用而不是闲置的方法是通过在LayoutUpdated处理程序中设置一个标志。 This is working amazing except that brush changes (especially in animations) don't trigger LayoutUpdated. 除了笔刷更改(尤其是在动画中)不会触发LayoutUpdated之外,这令人惊奇。 In fact, I can't tell what they trigger at all, but finding out would help me avoid busily rendering every single loop pass. 实际上,我根本无法说出它们触发了什么,但是找出来将有助于我避免忙于渲染每个循环遍历。 Can anyone help me? 谁能帮我?

I'm not sure if this will help your situation but there is a completed event for animations. 我不确定这是否可以帮助您解决问题,但是动画已完成。 Perhaps you could set a flag when animation completes, then check the flag in your render loop. 也许可以在动画完成时设置一个标志,然后在渲染循环中检查该标志。

XAML XAML

<Window.Resources>
    <Storyboard x:Key="Storyboard1">

      <ColorAnimation  Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
                       Storyboard.TargetName="rectangle"
                       BeginTime='0:0:0'
                       Duration='0:0:3'
                       From='White'
                       To='Blue'
                       Completed='ColorAnimation_Completed'>

      </ColorAnimation>
    </Storyboard>
  </Window.Resources>
  <Window.Triggers>
    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
      <BeginStoryboard Storyboard="{StaticResource Storyboard1}" />
    </EventTrigger>

  </Window.Triggers>
  <Grid>
    <Rectangle x:Name="rectangle"
               Fill="#FFF4F4F5"
               HorizontalAlignment="Left"
               Height="93"
               Margin="57,64,0,0"
               Stroke="Black"
               VerticalAlignment="Top"
               Width="130" />

  </Grid>

Code

    private bool _colorChanged = false;
    private void ColorAnimation_Completed(object sender, EventArgs e) {
      _colorChanged = true;

      // restart animation here if necessary
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM