`

wp wp8:自定义控件 自定义progressbar

    博客分类:
  • wp
wp 
阅读更多
MProgress.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;

namespace MyControl.M
{
    public partial class MProgress : UserControl
    {


        public Color ForeColor
        {
            get { return (Color)GetValue(MProgressForeColorProperty); }
            set { SetValue(MProgressForeColorProperty, value); }
        }
        public Color BackColor
        {
            get { return (Color)GetValue(MProgressBackColorProperty); }
            set { SetValue(MProgressBackColorProperty, value); }
        }

        public static readonly DependencyProperty MProgressForeColorProperty =
            DependencyProperty.Register("ForeColor", typeof(Color), typeof(MProgress),
            new PropertyMetadata(Colors.Black, OnColorChanged));

        public static readonly DependencyProperty MProgressBackColorProperty =
            DependencyProperty.Register("BackColor", typeof(Color), typeof(MProgress),
            new PropertyMetadata(Colors.White, OnColorChanged));

       

        private static void OnColorChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            MProgress progress = obj as MProgress;
            if (e.Property == MProgressForeColorProperty)
            {

                progress.textBlock.Foreground = new SolidColorBrush((Color)e.NewValue);
            }
            if (e.Property == MProgressBackColorProperty)
            {

                progress.LayoutRoot.Background = new SolidColorBrush((Color)e.NewValue);
            }
        }

        private DispatcherTimer timer = null;

        public MProgress()
        {
            InitializeComponent();
            timer = new DispatcherTimer();
        }

        public void setText(String text)
        {
            textBlock.Text = text;
        }

        public void startLoading()
        {
            //progressBar.Visibility = Visibility.Collapsed;
            progressBar.Visibility = System.Windows.Visibility.Visible;
            LayoutRoot.Visibility = System.Windows.Visibility.Visible;
        }

        public void stopLoading()
        {
            //progressBar.Visibility = Visibility.Collapsed;
            progressBar.Visibility = System.Windows.Visibility.Visible;
            LayoutRoot.Visibility = System.Windows.Visibility.Collapsed;
        }

        public void startLoadingWithText(String text)
        {
            textBlock.Text = text;
            progressBar.Visibility = System.Windows.Visibility.Visible;
            LayoutRoot.Visibility = System.Windows.Visibility.Visible;
           
        }

        public void stopLoadingWithText(String text)
        {
            timer.Stop();

            textBlock.Text = text;
            progressBar.Visibility = System.Windows.Visibility.Collapsed;

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += (s, ev) =>
            {
                LayoutRoot.Visibility = System.Windows.Visibility.Collapsed;
                timer.Stop();
            };
            timer.Start();

        }

    }
}

========================================================================================

MProgress.xaml

<UserControl x:Class="MyControl.M.MProgress"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    x:Name="this">

    <Grid x:Name="LayoutRoot" HorizontalAlignment="Stretch"
        VerticalAlignment="Stretch"
        Background="#ee000000"
        Visibility="Collapsed">
       
        <StackPanel Orientation="Vertical"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Center">

            <ProgressBar
                x:Name="progressBar"
                HorizontalAlignment="Stretch"
                         Height="50"
                         VerticalAlignment="Center"
                         IsIndeterminate="true"
                         Visibility="Collapsed" />
            <TextBlock x:Name="textBlock"
                Foreground="White"
                       Text=""
                       Margin="5,0,0,5"
                       TextWrapping="Wrap"
                       FontSize="22"
                       Height="35"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"/>

        </StackPanel>
    </Grid>
   
</UserControl>
========================================================================================

使用方式:

<phone:PhoneApplicationPage
    x:Class="MyControl.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:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sam="clr-namespace:MyControl.M"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
     
    >


    <Grid x:Name="LayoutRoot" Background="White">
        
         <Grid.RowDefinitions>
            <RowDefinition Height="200"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
         </Grid.RowDefinitions>
            <sam:MProgress HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="bar" Grid.RowSpan="2"></sam:MProgress>
           
            <Button Grid.Row="0" Content="Button1" Height="72" x:Name="myButton11" Width="160" Click="click" Margin="10"/>
           
    </Grid>

</phone:PhoneApplicationPage>



效果:









注意:

使用时 指定命名空间xmlns:sam="clr-namespace:MyControl.M"

使用时注意调用开头<sam: />

类一定要是public的 否则不能在配置文件中调用

分享到:
评论

相关推荐

    多种风格的Android 自定义progressbar控件

    本项目"多种风格的Android自定义progressbar控件"提供了多种不同设计风格的进度条,让开发者可以根据自己的应用主题和需求选择合适的样式。 首先,我们来看看自定义ProgressBar的基本概念。在Android中,可以通过...

    Android开发中自定义ProgressBar控件的方法示例

    Android开发中自定义ProgressBar控件的方法示例主要介绍了Android开发中自定义ProgressBar控件的方法,结合实例形式分析了自定义ProgressBar控件的定义与使用方法。 知识点1:自定义ProgressBar控件的定义 在...

    自定义控件vb自定义控件textbox等等

    本项目中的“自定义控件vb自定义控件textbox等等”显然涉及到VB中对常见控件如TextBox的重定义和定制化,以及可能包括其他自定义控件如进度条和输入框等。 TextBox控件是VB中基础且常用的文本输入控件,通常用于...

    自定义控件ProgressBar

    自定义控件ProgressBar允许开发者根据项目需求定制更丰富的视觉效果和交互方式,提升用户体验。在这个特定的案例中,我们看到的"自定义控件ProgressBar"是用来作为整个界面的下载背景图,这意味着它可能具有更独特的...

    C# WinForm 自定义控件开发系列

    8. **自定义控件实例** - **CheckBoxButton**:结合了`CheckBox`和`Button`的功能,点击时既可改变状态也可触发事件。 - **LabelProgressBar**:一个混合了文本标签和进度条的控件,可以同时显示进度和文字信息。 ...

    android 开发进阶 自定义控件 类似 TextView

    7. **子视图管理**:如果需要,还可以在自定义控件内部添加其他视图,如ImageView或ProgressBar,形成复合控件。 8. **性能优化**:在设计自定义控件时,要考虑到性能因素,避免在`onDraw()`方法中执行耗时操作,...

    android自定义控件:图文编辑框,菊花样式Progressbar

    本文将深入探讨如何创建一个图文编辑框以及实现菊花样式(也称 loading 动画)的Progressbar,这两个自定义控件。 首先,我们要理解图文编辑框的概念。在Android中,一个图文编辑框通常指的是可以同时展示文本和...

    WP8.1自定义Progressbar

    在本教程中,我们将探讨如何在WP8.1中实现一个仿Android风格的自定义Progressbar。这个Progressbar不仅在外观上接近Android,还可能包含一些Android特有的交互特性。 首先,让我们理解什么是Progressbar。...

    Android自定义电量控件百分比控制

    在Android开发中,自定义控件是提升应用界面独特性和用户体验的重要手段。本文将深入探讨如何创建一个自定义电量控件,实现百分比控制,并不显示数字,同时提供大小和颜色的可定制性,确保其在不同场景下都能优雅地...

    C# 自定义控件实例 C# 自定义控件实例

    在C#编程中,自定义控件是一种非常重要的技术,它允许开发者根据特定需求扩展或创建新的用户界面元素。自定义控件可以是现有控件的简单修改,也可以是完全新颖的设计,为应用程序提供独特的交互体验。在这个实例中,...

    C#自定义控件合集-SunnyUI.rar

    进度条控件(ProgressBar)通常用于表示一个任务的进度,如下载、安装或处理数据。在SunnyUI中,自定义的进度条控件可能具备更美观的外观,比如自定义颜色、形状或动态效果,以提供更好的反馈给用户。此外,它可能还...

    C# Winform 自定义进度条ProgressBar

    在C# Winform开发中,有时我们希望对系统的标准控件进行自定义...通过学习和实践这个"C# Winform 自定义进度条ProgressBar"的示例,开发者可以更好地理解Winform控件的绘制原理,并为自己的项目增添更多的个性化元素。

    android中自定义progressbar组件

    本篇文章将深入探讨如何在Android中自定义一个基于逐帧动画的ProgressBar组件,即自定义loading进度条。 首先,我们来了解ProgressBar的基本概念。ProgressBar是Android系统提供的一个用于显示进度的视图组件,它有...

    Android之自定义ProgressBar

    默认样式可能无法满足所有设计要求,因此我们需要自定义控件来扩展这些功能。 自定义ProgressBar主要涉及以下几个步骤: 1. 创建XML布局文件: 在res/layout目录下创建一个新的XML布局文件,定义自定义ProgressBar...

    Android 自定义头部控件

    在Android应用开发中,自定义头部控件是一个常见的需求,它可以为应用提供独特的用户体验和界面设计。本篇文章将深入探讨如何实现一个自定义的多变头部控件,以供开发者们借鉴和学习。 首先,我们要理解头部控件...

    .net Compact 下的自定义ProgressBar源码

    8. **代码结构**:良好的代码组织和注释对于理解并维护自定义控件至关重要。源码应该清晰地划分各个功能模块,同时提供足够的注释以解释关键代码段的作用。 综上所述,这个自定义ProgressBar源码提供了在.NET ...

    安卓自定义控件相关-ProgressWheel支持进度显示的圆形ProgressBar.zip

    在Android开发中,自定义控件是提升应用界面独特性和用户体验的重要手段。"ProgressWheel"是一个专门用于显示进度的圆形ProgressBar,它为开发者提供了一种更美观、更灵活的方式来展示加载或进度信息。这个压缩包...

    android自定义VIEW之下载控件ProgressBar

    在本教程中,我们将深入探讨如何自定义一个专门用于显示下载进度的ProgressBar,即“下载控件”。这个控件不仅展示了进度,还能够以圆角矩形的形式呈现,并且可以灵活地调整颜色,以适应不同的设计风格。 首先,...

    WPF自定义进度条控件,横竖都有

    在本文中,我们将深入探讨如何在Windows Presentation Foundation (WPF) 中自定义进度条控件,以实现横置和竖置两种显示方式。WPF 是.NET Framework 的一部分,它为开发人员提供了丰富的用户界面(UI)框架,支持2D...

    c#自定义控件及调用实例

    本实例关注的是如何在C#中自定义一个水平比例的ProgressBar控件,即`meter`控件,支持颜色变化的功能。 首先,要创建自定义控件,你需要继承已有的Windows Forms控件。在这个例子中,我们可能会从`System.Windows....

Global site tag (gtag.js) - Google Analytics