程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> 背水一戰 Windows 10 (34),背水一戰34

背水一戰 Windows 10 (34),背水一戰34

編輯:關於.NET

背水一戰 Windows 10 (34),背水一戰34


[源碼下載]


背水一戰 Windows 10 (34) - 控件(進度類): RangeBase, Slider, ProgressBar, ProgressRing



作者:webabcd


介紹
背水一戰 Windows 10 之 控件(進度類)

  • RangeBase
  • Slider
  • ProgressBar
  • ProgressRing



示例
1、RangeBase(基類) 的示例
Controls/ProgressControl/RangeBaseDemo.xaml

<Page
    x:Class="Windows10.Controls.ProgressControl.RangeBaseDemo"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Controls.ProgressControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">
        <StackPanel Margin="10 0 10 10">

            <TextBlock Name="lblMsg" Margin="5" />
            
            <!--
                Slider - 滑動條控件,繼承自 RangeBase,下面介紹 RangeBase 的相關知識點
                    Minimum - 范圍控件的最小值(double 類型)
                    Maximum - 范圍控件的最大值(double 類型)
                    Value - 范圍控件的當前值(double 類型)
                    SmallChange - 小變化步長(double 類型),按鍵盤的“上/下/左/右”鍵
                    LargeChange - 大變化步長(double 類型),按鍵盤的“PageUp/PageDown”鍵(經測試無效,另外 Home 鍵和 End 鍵是可用的)
                    ValueChanged - 范圍控件的當前值發生變化後觸發的事件
            -->

            <Slider Name="slider" Width="200" Margin="5" HorizontalAlignment="Left" Foreground="Orange" Background="Red" 
                    Minimum="1000" Maximum="2000" Value="1500" SmallChange="10" LargeChange="100" ValueChanged="slider_ValueChanged">
            </Slider>

        </StackPanel>
    </Grid>
</Page>

Controls/ProgressControl/RangeBaseDemo.xaml.cs

/*
 * RangeBase(基類) - 范圍控件基類(繼承自 Control, 請參見 /Controls/BaseControl/ControlDemo/)
 */

using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;

namespace Windows10.Controls.ProgressControl
{
    public sealed partial class RangeBaseDemo : Page
    {
        public RangeBaseDemo()
        {
            this.InitializeComponent();
        }

        private void slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
        {
            // RangeBaseValueChangedEventArgs
            //     OldValue - 范圍控件的之前的值
            //     NewValue - 范圍控件的當前的值
            lblMsg.Text = $"slider old value:{e.OldValue}, slider new value:{e.NewValue}";
        }
    }
}


2、Slider 的示例
Controls/ProgressControl/SliderDemo.xaml

<Page
    x:Class="Windows10.Controls.ProgressControl.SliderDemo"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Controls.ProgressControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">

        <Grid.Resources>
            <local:MyThumbToolTipValueConverter x:Key="MyThumbToolTipValueConverter" />
        </Grid.Resources>

        <!--
            Slider - 滑動條控件
                Header - 可以設置一個純文本,不能命中測試,空 Header 的話不會占用任何空間
                HeaderTemplate - 可以將 Header 設置為任何 xaml,且支持命中測試
                Orientation - 滑動條的布局方向
                    Horizontal - 水平放置
                    Vertical - 垂直放置
                IsDirectionReversed - 值的增加方向為左到右或下到上則為 false(默認值),反之為 true
                IsThumbToolTipEnabled - 是否在 thumb 旁顯示當前值的提示
                ThumbToolTipValueConverter - 在 thumb 旁顯示當前值的提示時所使用的 Converter
                TickPlacement - 如何顯示刻度線,Windows.UI.Xaml.Controls.Primitives.TickPlacement枚舉(None, TopLeft, BottomRight, Outside, Inline)
                TickFrequency - 刻度線的間隔
                StepFrequency - 每一步的間隔
                SnapsTo - 貼靠方式
                    StepValues - 按 StepFrequency 做 Snap(默認值)
                        通過鼠標拖動或鼠標點擊控制 Slider 時,其值是 StepFrequency 的整倍數(注:鍵盤控制時,步長來自於基類 RangeBase 的 SmallChange, LargeChange)
                    Ticks - 按 TickFrequency 做 Snap
                        通過鼠標拖動或鼠標點擊控制 Slider 時,其值是 TickFrequency 的整倍數(注:鍵盤控制時,步長來自於基類 RangeBase 的 SmallChange, LargeChange)
        
            注:可以通過 Foreground, Background 來設置 Slider 的部分狀態的顏色,更多的樣式設置還是要去修改控件模板
        -->
        <StackPanel Margin="10 0 10 10">

            <Slider Margin="5" Width="100" Value="20" HorizontalAlignment="Left" Foreground="Orange" Background="Red" 
                    Header="Slider" />

            <Slider Margin="5" Height="100" HorizontalAlignment="Left" Foreground="Orange" Background="Red" 
                    Orientation="Vertical" IsDirectionReversed="True" 
                    IsThumbToolTipEnabled="True" ThumbToolTipValueConverter="{StaticResource MyThumbToolTipValueConverter}">
                <Slider.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="Slider" Foreground="Red" />
                    </DataTemplate>
                </Slider.HeaderTemplate>
            </Slider>

            <Slider Margin="5" Width="800" Minimum="0" Maximum="800" HorizontalAlignment="Left"  Foreground="Orange" Background="Red" 
                    TickPlacement="Inline" TickFrequency="80" 
                    StepFrequency="100" SnapsTo="StepValues" />

        </StackPanel>
    </Grid>
</Page>

Controls/ProgressControl/SliderDemo.xaml.cs

/*
 * Slider - 滑動條控件(繼承自 RangeBase, 請參見 /Controls/ProgressControl/RangeBaseDemo.xaml)
 * Thumb - 可由用戶拖動的控件(Slider 內的可拖動部分就是一個 Thumb 控件)
 */

using System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;

namespace Windows10.Controls.ProgressControl
{
    public sealed partial class SliderDemo : Page
    {
        public SliderDemo()
        {
            this.InitializeComponent();
        }
    }

    // 為 Slider 的 ThumbToolTipValueConverter 提供 Converter
    public sealed class MyThumbToolTipValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            // 在 thumb 旁顯示的當前值的後面加一個百分號
            return value + "%";
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            return null;
        }
    }
}


3、ProgressBar 的示例
Controls/ProgressControl/ProgressBarDemo.xaml

<Page
    x:Class="Windows10.Controls.ProgressControl.ProgressBarDemo"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Controls.ProgressControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">
        <StackPanel Margin="10 0 10 10">

            <!--
                ProgressBar - 進度條控件
                    IsIndeterminate - 是否是無法確定進度的進度條
                    ShowPaused - 顯示暫停狀態
                    ShowError - 顯示錯誤狀態
            
                注:可以通過 Foreground, Background 來設置 ProgressBar 的部分狀態的顏色,更多的樣式設置還是要去修改控件模板
            -->

            <ProgressBar IsIndeterminate="True" Width="200" HorizontalAlignment="Left" 
                         Foreground="Orange" Background="Red"
                         ShowPaused="{Binding IsChecked, ElementName=radPaused}"
                         ShowError="{Binding IsChecked, ElementName=radError}" />

            <ProgressBar IsIndeterminate="False" Width="200" Minimum="0" Maximum="100" Value="50"  HorizontalAlignment="Left" Margin="0 20 0 0"  
                         Foreground="Orange" Background="Red"
                         ShowPaused="{Binding IsChecked, ElementName=radPaused}"
                         ShowError="{Binding IsChecked, ElementName=radError}"/>

            <StackPanel Orientation="Horizontal" Margin="0 20 0 0">
                <RadioButton x:Name="radRunning" GroupName="ProgressState" Content="Running" IsChecked="True"/>
                <RadioButton x:Name="radPaused" GroupName="ProgressState" Content="Paused"/>
                <RadioButton x:Name="radError" GroupName="ProgressState" Content="Error"/>
            </StackPanel>

        </StackPanel>
    </Grid>
</Page>

Controls/ProgressControl/ProgressBarDemo.xaml.cs

/*
 * ProgressBar - 進度條控件(繼承自 RangeBase, 請參見 /Controls/ProgressControl/RangeBaseDemo.xaml)
 */

using Windows.UI.Xaml.Controls;

namespace Windows10.Controls.ProgressControl
{
    public sealed partial class ProgressBarDemo : Page
    {
        public ProgressBarDemo()
        {
            this.InitializeComponent();
        }
    }
}


4、ProgressRing 的示例
Controls/ProgressControl/ProgressRingDemo.xaml

<Page
    x:Class="Windows10.Controls.ProgressControl.ProgressRingDemo"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Controls.ProgressControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">
        <StackPanel Margin="10 0 10 10">

            <!--
                ProgressRing - 進度圈控件
                    IsActive - 是否顯示
            -->
            <ProgressRing Margin="5" Foreground="White" Width="200" Height="200" HorizontalAlignment="Left" 
                          IsActive="{Binding IsChecked, ElementName=chkIsActive}"/>

            <CheckBox Name="chkIsActive" Margin="5" Content="IsActive" IsChecked="True" />
            
        </StackPanel>
    </Grid>
</Page>

Controls/ProgressControl/ProgressRingDemo.xaml.cs

/*
 * ProgressRing - 進度圈控件(繼承自 Control, 請參見 /Controls/BaseControl/ControlDemo/)
 */

using Windows.UI.Xaml.Controls;

namespace Windows10.Controls.ProgressControl
{
    public sealed partial class ProgressRingDemo : Page
    {
        public ProgressRingDemo()
        {
            this.InitializeComponent();
        }
    }
}



OK
[源碼下載]

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved