首页 新闻 会员 周边

(新手求助)WPF用户控件(LoadingWait.xaml)如何在(主窗体)程序运行时显示,结束后隐藏?(代码结构看详细)

0
[已解决问题] 解决于 2018-01-31 15:52

单独做了个用户控件,用户控件后台代码继承了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>
大da脸的主页 大da脸 | 初学一级 | 园豆:73
提问于:2018-01-30 13:38
< >
分享
最佳答案
0

没那么麻烦,给你个简单方法 —— 你把这个UiElement直接放到窗口 顶层元素就行了。然后控制显示与否就行了。

比如

{

  RootGrid

  {

    Grid你原来的;

    你这个UserControl;

  }

}

奖励园豆:5
花飘水流兮 | 专家六级 |园豆:13560 | 2018-01-30 17:51
其他回答(1)
0

微软MSDN上都说了:

SplashScreen Class

爱编程的大叔 | 园豆:30839 (高人七级) | 2018-01-30 15:12

能指点下吗,MSDN上面全是英文,看不懂啊

支持(0) 反对(0) 大da脸 | 园豆:73 (初学一级) | 2018-01-30 15:27

@落幕: 你这个代码那就简单了,你可以通过控制 Visibility=true/false 来控制是否显示。

支持(0) 反对(0) 爱编程的大叔 | 园豆:30839 (高人七级) | 2018-01-30 17:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册