[WPF] twenty-four chapters based learning range controls

Original: [WPF] twenty-four chapters based learning range controls

  WPF provides three concepts using a range of controls. These controls using a specific value between the minimum and maximum values. These controls --ScrollBar, ProgressBar and Slider-- inherit from RangeBase class (the class has inherited from the Control class). Although they use the same abstraction (range), but yet very different way of working,

  The following table shows the class definition RangeBase properties:

Class attribute table RangeBase

 

   Usually better than the direct use of the ScrollBar control. More advanced ScrollViewer control (encapsulates two ScrollBar control) is usually more useful. Slider and ProgressBar controls are more practical, they are often alone.

A, Slider

  Slider controls are occasionally used in special controls - for example, when the number itself is not particularly important to use this control to set the value. As another example, set the volume of the media player through the slider from side to side, drag the slider is very reasonable. Approximate position of the slider indicates the relative volume (normal, small volume, large volume), but behind the numbers for the user does not make sense.

  Slider simple example the following effects:

<Window x:Class="Controls.SliderTest"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="SliderTest" Height="300" Width="300">
    <StackPanel>
        <TextBlock Margin="10" TextWrapping="Wrap">
      A Delay of 0 and Interval of 1 make this a fast slider.
      Try clicking on either side of the thumb and holding down
      the mouse button.</TextBlock>

        <Slider Margin="10" TickFrequency="1" TickPlacement="TopLeft" 
            Maximum="10" Delay="0" Interval="1"
          >
        </Slider>

    </StackPanel>
</Window>
SliderTest

 

   Slider control important attributes defined in RangeBase class. In addition to these properties, you may also be used all the attributes listed in the table.

Slider class attribute table attached

 

   The chart below compares the use of different scale settings Slider control:

<Window x:Class="Controls.SlidersCompared"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="SlidersCompared" Height="300" Width="408.271">
    <Grid>
        <StackPanel Margin="10">
            <TextBlock Margin="0,0,0,5">Normal Slider (Max=100, Val=10)</TextBlock>
            <Slider Maximum="100" Value="10"></Slider>
            <TextBlock Margin="0,15,0,5">Slider with Tick Marks (TickFrequency=10, TickPlacement=BottomRight)</TextBlock>
            <Slider Maximum="100" Value="10" TickFrequency="10" TickPlacement="BottomRight"></Slider>
            <TextBlock Margin="0,15,0,5">Slider with Irregular Tick Marks (Ticks=0,5,10,15,25,50,100)</TextBlock>
            <Slider Maximum="100" Value="10" Ticks="0,5,10,15,25,50,100"  TickPlacement="BottomRight"></Slider>
            <TextBlock Margin="0,15,0,5" TextWrapping="Wrap">Slider with a Selection Range (IsSelectionRangeEnabled=True, SelectionStart=25, SelectionEnd=75)</TextBlock>
            <Slider Maximum="100" Value="10" TickFrequency="10" TickPlacement="BottomRight"
                IsSelectionRangeEnabled="True" SelectionStart="25" SelectionEnd="75"></Slider>
        </StackPanel>
    </Grid>
</Window>
SlidersCompared

 

 二、ProgressBar

  ProgressBar控件指示长时间运行任务的进度。与Slider控件不同,ProgressBar控件不能与用户进行交互。反而,需要由代码递增Value属性值(从技术角度看,WPF规则建议不将ProgressBar作为控件,因为它无法响应鼠标动作和键盘输入)。ProgressBar控件具有4个设备无关单位的最小高度。如果希望看到更大、更传统的进度条,需要设置Height属性(或将它放入具有适当固定尺寸的容器中)。

  使用ProgressBar控件的通常方式是将它作为长时间运行的状态指示其,甚至可能不知道该任务需要执行多长时间。有趣的是(也很奇特),可通过将IsIndeterminate属性设置为true来完成这一工作:

<ProgressBar Height="50"  IsIndeterminate="True"></ProgressBar>

  最终效果如下图所示:

 

   当设置IsIndeterminate属性时,不再使用Minimum、Maximum和Value属性。ProgressBar控件会周期性地显示从左向右跳动的绿色脉冲,这是通用的Windows约定,表示工作正在进行中。在应用程序的状态栏中,这种指示器非常合理。例如,可使用它指示正在连接远程服务器以便获取信息。

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12285975.html