触发器中控件依赖属性绑定失效

问题:

该触发器触发后,stitchOverTopControl中的IsRotate依赖属性没有更新。
<Trigger Property="WarningLevel" Value="2">
   <Setter Property="Content" >
      <Setter.Value>
           <Grid Margin="0,-35,0,0" x:Name="topGrid" VerticalAlignment="Top" >
                <local:StitchOverTopControl HorizontalAlignment="Center" x:Name="stitchOverTopControl" IsRotate="{Binding ElementName=self,Path=IsVaild}">
                </local:StitchOverTopControl>
           </Grid>
      </Setter.Value>
    </Setter>
</Trigger>

原因:

绑定源更新(IsVaild)时,控件stitchOverTopControl仍未显示,则会错过此次更新。

当控件显示后想要获取绑定源的最新值,则可在控件中增加Load事件,在MyControl_Loaded中获取最新的绑定源。

 

<Style TargetType="local:StitchOverTopControl">
            <EventSetter Event="Loaded" Handler="StitchOverTopControl_Loaded"/>
</Style>

 

private void StitchOverBottomControl_Loaded(object sender, RoutedEventArgs e)
{
    var stitchOverBottomControl = sender as StitchOverBottomControl;
    stitchOverBottomControl.IsRotate = IsVaild;
}

 

posted @ 2024-11-21 15:44  LXLR  阅读(2)  评论(0编辑  收藏  举报