当用户可以看到视图(BiometricVM)时,我试图获取触发器。有问题的视图在另一个视图(ParentView.xaml)中实例化并隐藏。我在这里读了几个答案,但没有一个有效。以下是相关代码:
ParentView.xaml
<Border BorderBrush="Black" BorderThickness="1" Background="#80000000" Visibility="{Binding BiometricViewVisible, Converter={StaticResource BooleanToVisibilityConverter}}" Grid.RowSpan="2" >
<Grid>
<WrapPanel HorizontalAlignment="Center" VerticalAlignment="Center" >
<Border Style="{StaticResource DefaultWindowBorder}" >
<Grid Background="White" >
<vw:BiometricView DataContext="{Binding BiometricVM}" Visibility="{Binding BiometricViewVisible, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Grid>
</Border>
</WrapPanel>
</Grid>
</Border>
ParentViewModel.cs
public bool BiometricViewVisible
{
get
{
return _biometricViewVisible;
}
set
{
_biometricViewVisible = value;
OnPropertyChanged(nameof(BiometricViewVisible));
}
}
BiometricView.xaml
<i:Interaction.Triggers>
<i:EventTrigger EventName="IsVisibleChanged">
<i:InvokeCommandAction Command="{Binding Path=OnLoadedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
这是未被调用的命令(OnLoadedCommand)。
对此事的任何帮助将不胜感激。
答案 0 :(得分:0)
为什么不能简单地在BiometricViewVisible
源属性的setter中调用命令?
public bool BiometricViewVisible
{
get
{
return _biometricViewVisible;
}
set
{
_biometricViewVisible = value;
OnPropertyChanged(nameof(BiometricViewVisible));
if (value)
{
OnLoadedCommand.Execute(null);
}
}
}
由于Visibility
的{{1}}属性直接绑定到此源属性,因此只有当此属性设置为true时,视图才会变为可见,因此您无需处理任何事件