这应该相当简单——首先添加一个像边框这样的覆盖层和默认隐藏的“购买”按钮。只需确保覆盖层是根的最后一个子节点,以便它始终出现在顶部:
<Grid x:Name="LayoutRoot">
<!-- Main content here -->
<Border x:Name="overlay" RowSpan="10" ColumnSpan="10"
Opacity="0.5" Background="#666"
Visibility="Collapsed" />
<Button x:Name="btnPurchase"
Content="Purchase"
HorizontalAlignment="Center" VerticalAlignment="Center"
Command="{Binding StartPurchaseCommand}"
Visibility="Collapsed" />
</Grid>
现在添加一个“购买”视觉状态来显示叠加+按钮:
<Grid x:Name="LayoutRoot">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="PurchaseStates">
<VisualState x:Name="TrialState" />
<VisualState x:Name="PurchaseRequired">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="overlay" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="btnPurchase" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
然后,只要试用期结束,只需调用VisualStateManager.GoToState(this, "PurchaseRequired", true)
启动即可。