WindowsPhone第三方控件ProgressOverlay的使用

在WIndowsPhone应用中有时候需要用到进行状态条,我找到了一个第三方的控件库,可以很方便的向应用中添加这个状态条。

 

一、先决条件

下载Coding4Fun Tools(地址:http://coding4fun.codeplex.com/releases/view/92875)

 

二、建立一个空的WindowsPhone项目

 

三、在引用中添加对 Coding4Fun.Phone.Controls.dll 的引用

四、在XAML中添加的<phone:PhoneApplicationPage>标签内添加以下代码

xmlns:slToolkit ="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:c4f="clr-namespace:Coding4Fun.Phone.Controls;assembly=Coding4Fun.Phone.Controls"
    xmlns:Converters="clr-namespace:Coding4Fun.Phone.Controls.Converters;assembly=Coding4Fun.Phone.Controls"
    

在最后一个</Grid>标签之前添加

<c4f:ProgressOverlay Name="progressOverlay" Visibility="Visible" Grid.RowSpan="2" Margin="0,0,0,-24">
            <c4f:ProgressOverlay.Resources>
                <Converters:VisibilityToBooleanConverter x:Key="VisToBoolConverter" />
            </c4f:ProgressOverlay.Resources>
            <StackPanel>
                <TextBlock HorizontalAlignment="Center" Name="textBlockStatus">加载中</TextBlock>
                <slToolkit:PerformanceProgressBar IsIndeterminate="{Binding ElementName=progressOverlay, Path=Visibility, Converter={StaticResource VisToBoolConverter}}"/>
            </StackPanel>
        </c4f:ProgressOverlay>

完整的XAML代码如下

<phone:PhoneApplicationPage 
    x:Class="PopupTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:slToolkit ="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:c4f="clr-namespace:Coding4Fun.Phone.Controls;assembly=Coding4Fun.Phone.Controls"
    xmlns:Converters="clr-namespace:Coding4Fun.Phone.Controls.Converters;assembly=Coding4Fun.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot 是包含所有页面内容的根网格-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel 包含应用程序的名称和页标题-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="页面名称" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - 在此处放置其他内容-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        
        </Grid>
        <c4f:ProgressOverlay Name="progressOverlay" Visibility="Visible" Grid.RowSpan="2" Margin="0,0,0,-24">
            <c4f:ProgressOverlay.Resources>
                <Converters:VisibilityToBooleanConverter x:Key="VisToBoolConverter" />
            </c4f:ProgressOverlay.Resources>
            <StackPanel>
                <TextBlock HorizontalAlignment="Center" Name="textBlockStatus">加载中</TextBlock>
                <slToolkit:PerformanceProgressBar IsIndeterminate="{Binding ElementName=progressOverlay, Path=Visibility, Converter={StaticResource VisToBoolConverter}}"/>
            </StackPanel>
        </c4f:ProgressOverlay>
    </Grid>
 
</phone:PhoneApplicationPage>

progressOverlay的Visibility设为visible,

你只需要在后台的代码中控制progressOverlay的Visibility就可以了,

当你后台的加载结束之后你就可以在你的方法中添加

progressOverlay.Visibility = System.Windows.Visibility.Collapsed;

即可完成progressOverlay的隐藏。

posted @ 2012-11-14 22:04  CimiChen  阅读(931)  评论(0编辑  收藏  举报