【发布时间】:2017-10-31 15:57:02
【问题描述】:
我正在学习 c# (UWP),并在 XAML 中创建了一个通知文本块。
这里是:
<Storyboard x:Name="notificationPanel1">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="notificationBorder">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Thickness>0,-80,0,0</Thickness>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="notificationBorder">
<EasingDoubleKeyFrame KeyTime="0" Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<BackEase EasingMode="EaseInOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="75">
<EasingDoubleKeyFrame.EasingFunction>
<BackEase EasingMode="EaseInOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="75">
<EasingDoubleKeyFrame.EasingFunction>
<BackEase EasingMode="EaseInOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Grid>
....
<Border x:Name="notificationBorder" BorderBrush="{x:Null}" VerticalAlignment="Top" Margin="0,-80,0,0" RenderTransformOrigin="0.5,0.5">
<Border.RenderTransform>
<CompositeTransform/>
</Border.RenderTransform>
<TextBlock x:Name="notificationTxt" TextWrapping="Wrap" Padding="0" TextAlignment="Center" Foreground="White" Text="sdfdsfsdf" Margin="0,15"/>
</Border>
....
</Grid>
有没有更好的方法来做到这一点?因为,现在我必须将此 XAML 复制到所有页面。
Mb 动态生成这个?但是我不知道怎么做,你能给我提示吗?
谢谢
【问题讨论】:
-
您需要将它放在用户控件中,然后在所有页面中使用它!
-
@PedroLamas,感谢您的回复。正如我所说,我正在学习 C#,所以现在我不知道如何创建自定义控件。但我会在谷歌上检查它。谢谢
-
从一个用户控件开始(它就像一个页面,你可以直接从visual studio添加它);因为你还在学习,它会比自定义控件更容易处理!
-
不错。谢谢你:)
-
我发现以下课程对控件很有帮助mva.microsoft.com/en-US/training-courses/…