📜  Silverlight-内容模型

📅  最后修改于: 2020-11-19 08:30:53             🧑  作者: Mango


这些按钮为模型内容提供了一种形式的内容。模型在控件中大量出现。这个想法很简单。它将接受任何内容,而不仅仅是文本。如果要创建一个真正的异国情调的按钮,甚至可以在其中放置其他内容控件,例如文本框和按钮(并将静止元素嵌套在其中)。令人怀疑的是,这样的接口是否有意义,但是否有可能。

让我们看一个简单的示例,其中包含按钮,按钮内的其他内容控件。


   
    
    
       
        
    
    

编译并执行上述代码后,您将看到以下按钮。

内容控制

范围控制

滚动条和滑块控件密切相关。它们都允许用户从特定范围内选择输入值。按照惯例,这些控件表示不同的事物。滚动条通常用于将位置设置为阴囊区域,而滑块则用于指定一些值或设置。这些只是约定;控件具有相似的行为和API。

范围控件易于使用。您指定最小值和最大值以指示您希望滑块表示的值的范围。 Value属性将随着拖动的使用而变化。

Slider类的层次继承如下:

滑块的继承

下面给出的是Slider的常用属性

Sr. No. Property & Description
1

Header

Gets or sets the content for the control’s header.

2

HeaderProperty

Identifies the Header dependency property.

3

HeaderTemplate

Gets or sets the DataTemplate used to display the content of the control’s header.

4

HeaderTemplateProperty

Identifies the HeaderTemplate dependency property.

5

IntermediateValue

Gets or sets the value of the Slider while the user is interacting with it, before the value is snapped to either the tick or step value. The SnapsTo property specifies the value of slider.

6

IntermediateValueProperty

Identifies the IntermediateValue dependency property.

7

IsDirectionReversed

Gets or sets a value that indicates the direction of increasing value.

8

IsDirectionReversedProperty

Identifies the IsDirectionReversed dependency property.

9

IsThumbToolTipEnabled

Gets or sets a value that determines whether the slider value is shown in a tool tip for the Thumb component of the Slider.

10

IsThumbToolTipEnabledProperty

Identifies the IsThumbToolTipEnabled dependency property.

11

Orientation

Gets or sets the orientation of a Slider.

12

OrientationProperty

Identifies the Orientation dependency property.

13

StepFrequency

Gets or sets the value part of a value range that steps should be created for.

14

StepFrequencyProperty

Identifies the StepFrequency dependency property.

15

ThumbToolTipValueConverter

Gets or sets the converter logic that converts the range value of the Slider into tool tip content.

16

ThumbToolTipValueConverterProperty

Identifies the ThumbToolTipValueConverter dependency property.

17

TickFrequency

Gets or sets the increment of the value range that ticks should be created for.

18

TickFrequencyProperty

Identifies the TickFrequency dependency property.

19

TickPlacement

Gets or sets a value that indicates where to draw tick marks in relation to the track.

20

TickPlacementProperty

Identifies the TickPlacement dependency property.

下面给出的是Slider类中的常用事件

Sr. No. Event & Description
1

ManipulationCompleted

Occurs when a manipulation on the UIElement is complete. (Inherited from UIElement)

2

ManipulationDelta

Occurs when the input device changes position during a manipulation. (Inherited from UIElement)

3

ManipulationInertiaStarting

Occurs when the input device loses contact with the UIElement object during a manipulation and inertia begins. (Inherited from UIElement)

4

ManipulationStarted

Occurs when an input device begins a manipulation on the UIElement. (Inherited from UIElement)

5

ManipulationStarting

Occurs when the manipulation processor is first created. (Inherited from UIElement)

6

ValueChanged

Occurs when the range value changes. (Inherited from RangeBase)

下面给出的是Slider类中的常用方法

Sr. No. Method & Description
1

OnManipulationCompleted

Called before the ManipulationCompleted event occurs. (Inherited from Control)

2

OnManipulationDelta

Called before the ManipulationDelta event occurs. (Inherited from Control)

3

OnManipulationInertiaStarting

Called before the ManipulationInertiaStarting event occurs. (Inherited from Control)

4

OnManipulationStarted

Called before the ManipulationStarted event occurs. (Inherited from Control)

5

OnManipulationStarting

Called before the ManipulationStarting event occurs. (Inherited from Control)

6

OnMaximumChanged

Called when the Maximum property changes. (Inherited from RangeBase)

7

OnMinimumChanged

Called when the Minimum property changes. (Inherited from RangeBase)

8

OnValueChanged

Fires the ValueChanged routed event. (Inherited from RangeBase)

9

SetBinding

Attaches a binding to a FrameworkElement, using the provided binding object. (Inherited from FrameworkElement)

10

SetValue

Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)

让我们看一个简单的示例,其中添加了一个滑块和一个椭圆,并且滑块控制了椭圆的宽度。

 
   
   
    
       
          
          
        
        
        
            
       
        
    
    

下面给出的是值更改事件的实现,它是C#。

using System.Windows; 
using System.Windows.Controls; 
 
namespace SliderExample { 

   public partial class MainPage : UserControl { 
    
      public MainPage() { 
         InitializeComponent(); 
      }
      
      private void Slider_ValueChanged(object sender, 
         RoutedPropertyChangedEventArgs e) { 
            
            if (myEllipse != null) { 
               myEllipse.Width = e.NewValue; 
            } 
      } 
   } 
}

编译并执行上述代码后,您将看到以下输出。如您所见,当您从左向右移动滑块时,椭圆宽度会增加。

添加滑块和椭圆