繁体   English   中英

如何在Windows Universal Apps中显示带有文本的进度响铃?

[英]How to show a progress ring with a text in Windows Universal Apps?

我正在将Windows Phone 8应用程序迁移到Windows Universal Apps。 在那里,我使用进度指示器显示一些文本,如“正在加载请等待......”,直到我收到Web服务调用的响应表单服务器。 现在我想在Windows 8.1 App中实现相同的目的。 在Windows 8.1中有进度环控件,但是Text属性不存在。 任何人都可以建议一些示例代码如何实现这一目标。 我想在我的整个应用程序中使用它?

甚至,我以前在Progress Indicator中显示的文本都存储在本地存储中的json文件中。

另外,我想使用Dispatcher和c#不使用Xaml来实现这一点。

您可以创建自己的UserControl,其中包含消息的ProgressRing和TextBlock,这是一个示例:

<UserControl
x:Class="YourNamespace.ProgressRingWithText"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:YourNamespace"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400"
x:Name="uc">

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <ProgressRing IsActive="{Binding IsActive, ElementName=uc}"/>
    <TextBlock Text="{Binding Text, ElementName=uc}" HorizontalAlignment="Center"/>
</Grid>

而C#:

public sealed partial class ProgressRingWithText : UserControl
{
    public bool IsActive
    {
        get { return (bool)GetValue(IsActiveProperty); }
        set { SetValue(IsActiveProperty, value); }
    }

    // Using a DependencyProperty as the backing store for IsActive.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty IsActiveProperty =
        DependencyProperty.Register("IsActive", typeof(bool), typeof(ProgressRingWithText), new PropertyMetadata(false));

    public string Text
    {
        get { return (string)GetValue(TextProperty); }
        set { SetValue(TextProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TextProperty =
        DependencyProperty.Register("Text", typeof(string), typeof(ProgressRingWithText), new PropertyMetadata("Loading..."));

    public ProgressRingWithText()
    {
        this.InitializeComponent();
    }
}

然后,可以在将这些属性添加到窗口/页面时引用这些属性。

您甚至可以更进一步使用布尔到可见性转换器将IsActive属性转换为可见性,以便更改TextBlock的可见性。

当然,这是一个非常简单的用户界面,但可以随意使用它,看看它是否适合你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM