单独做了个用户控件,用户控件后台代码继承了LoadingWait : UserControl(应该属于用户控件吧)
用户控件(LoadingWait.xaml)效果图(下图)
如何在(主窗体)程序运行时显示,结束后隐藏?
LoadingWait.xaml代码(下)
<UserControl x:Class="Yuyue.WPF.LoadingWait" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" IsVisibleChanged="HandleVisibleChanged"> <UserControl.Background> <SolidColorBrush Color="Black" Opacity="0" /> </UserControl.Background> <UserControl.Resources> <SolidColorBrush Color="#FF007BE5" x:Key="CirclesColor" /> <!--<SolidColorBrush Color="Black" x:Key="BackgroundColor" Opacity=".20" />--> </UserControl.Resources> <Viewbox Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid x:Name="LayoutRoot" Background="Transparent" ToolTip="Please wait...." HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBlock Text="Loading..." HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14" Foreground="#FFE3953D" FontWeight="Bold" /> <Canvas RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Center" Width="120" Height="120" Loaded="HandleLoaded" Unloaded="HandleUnloaded" > <Ellipse x:Name="C0" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="1.0"/> <Ellipse x:Name="C1" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.9"/> <Ellipse x:Name="C2" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.8"/> <Ellipse x:Name="C3" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.7"/> <Ellipse x:Name="C4" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.6"/> <Ellipse x:Name="C5" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.5"/> <Ellipse x:Name="C6" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.4"/> <Ellipse x:Name="C7" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.3"/> <Ellipse x:Name="C8" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.2"/> <Canvas.RenderTransform> <RotateTransform x:Name="SpinnerRotate" Angle="0" /> </Canvas.RenderTransform> </Canvas> </Grid> </Viewbox> </UserControl>
没那么麻烦,给你个简单方法 —— 你把这个UiElement直接放到窗口 顶层元素就行了。然后控制显示与否就行了。
比如
{
RootGrid
{
Grid你原来的;
你这个UserControl;
}
}
微软MSDN上都说了:
能指点下吗,MSDN上面全是英文,看不懂啊
@落幕: 你这个代码那就简单了,你可以通过控制 Visibility=true/false 来控制是否显示。