Silverlight - 内容模型

按钮为模型内容提供了一种内容形式.模特在控件中出现了很多.这个想法很简单.它将接受任何内容,而不仅仅是文本.如果你想创建一个真正奇特的按钮,你甚至可以放置其他内容控件,如文本框和按钮(并在其中嵌入静态元素).令人怀疑的是这样的界面会有多大意义,但这是有可能的.

让我们看看一个带按钮的简单示例,内部按钮其他内容控件.

<UserControl x:Class = "ContentModel.MainPage" 
   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" 
   d:DesignHeight = "300" d:DesignWidth = "400">
   
   <Grid x:Name = "LayoutRoot" Background = "White"> 
	
      <Button Margin = "3" Height = "70" Width = "215"> 
         <Grid Margin = "5"> 
            <Polygon Points = "100,25 125,0 200,25 125,50" Fill = "LightSteelBlue" /> 
            <Polygon Points = "100,25 75,0 0,25 75,50" Fill = "LightGray"/> 
         </Grid> 
      </Button> 
		
   </Grid> 
	
</UserControl>

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

内容控件

RangeControl

滚动条和滑块控件密切相关.它们都允许用户从特定范围中选择输入值.通常,这些控制意味着不同的事物.滚动条通常用于将位置设置为阴囊区域,而滑块用于指定某个值或设置.这些只是惯例;控件具有类似的行为和API.

范围控件使用简单.您可以指定最小值和最大值,以指示您希望滑块表示的值范围. Value 属性会随着drags的使用而变化.

Slider 类的层次继承如下 :

Slider的继承

以下是常用的属性 of Slider .

Sr.不.属性&说明
1

Header

获取或设置控件标题的内容.

2

HeaderProperty

标识标头依赖属性.

3

HeaderTemplate

获取或设置用于显示控件标题内容的DataTemplate.

4

HeaderTemplateProperty

标识HeaderTemplate依赖项属性.

5

IntermediateValue

在将值捕捉到tick或step值之前,获取或设置用户与其进行交互时Slider的值. SnapsTo属性指定了滑块的值.

6

IntermediateValueProperty

标识IntermediateValue依赖项属性.

7

IsDirectionReversed

获取或设置一个值增值的方向.

8

IsDirectionReversedProperty

标识IsDirectionReversed依赖项属性.

9

IsThumbToolTipEnabled

获取或设置一个值,用于确定滑块是否为值显示在Slider的Thumb组件的工具提示中.

10

IsThumbToolTipEnabledProperty

标识IsThumbToolTipEnabled依赖项属性.

11

Orientation

获取或设置滑块的方向.

12

OrientationProperty

标识Orientation依赖属性.

13

StepFrequency

获取或设置应为其创建步骤的值范围的值部分.

14

StepFrequencyProperty

标识StepFrequency依赖属性.

15

ThumbToolTipValueConverter

获取或设置转换器逻辑,将Slider的范围值转换为工具提示内容.

16

ThumbToolTipValueConverterProperty

标识ThumbToolTipValueConverter依赖项属性.

17

TickFrequency

G ets或设置应为其创建滴答值的范围的增量.

18

TickFrequencyProperty

标识TickFrequency依赖属性.

19

TickPlacement

获取或设置一个值,该值指示相对于轨道绘制刻度线的位置.

20

TickPlacementProperty

标识TickPlacement依赖项属性.

以下是滑块中常用的事件 类.

Sr. No.活动&说明
1

ManipulationCompleted

在对UIElement的操作完成时发生. (继承自UIElement)

2

ManipulationDelta

在操作期间输入设备更改位置时发生. (继承自UIElement)

3

ManipulationInertiaStarting

在操作和惯性开始期间输入设备与UIElement对象失去联系时发生. (继承自UIElement)

4

ManipulationStarted

当输入设备开始对UIElement进行操作时发生. (继承自UIElement)

5

ManipulationStarting

首次创建操纵处理器时发生. (继承自UIElement)

6

ValueChanged

范围值更改时发生. (继承自RangeBase)

如下所示是滑块类中常用的方法.

Sr. No.方法&说明
1

OnManipulationCompleted

在ManipulationCompleted事件发生之前调用. (继承自Control)

2

OnManipulationDelta

在ManipulationDelta事件发生之前调用. (继承自Control)

3

OnManipulationInertiaStarting

在ManipulationInertiaStarting事件发生之前调用. (继承自Control)

4

OnManipulationStarted

在ManipulationStarted事件发生之前调用. (继承自Control)

5

OnManipulationStarting

在ManipulationStarting事件发生之前调用. (继承自Control)

6

OnMaximumChanged

最大属性更改时调用. (继承自RangeBase)

7

OnMinimumChanged

最小属性更改时调用. (继承自RangeBase)

8

OnValueChanged

触发ValueChanged路由事件. (继承自RangeBase)

9

SetBinding

使用提供的绑定对象将绑定附加到FrameworkElement. (继承自FrameworkElement)

10

SetValue

在DependencyObject上设置依赖项属性的本地值. (继承自DependencyObject)

示例

让我们看一个简单的例子,其中添加了一个滑块和一个椭圆,滑块控制着椭圆的宽度.

<UserControl x:Class = "SliderExample.MainPage" 
   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" d:DesignWidth = "640" d:DesignHeight = "480"> 
   
   <Grid x:Name = "LayoutRoot">
	
      <Grid.RowDefinitions> 
         <RowDefinition Height = "Auto" /> 
         <RowDefinition /> 
      </Grid.RowDefinitions>  
		
      <Slider Minimum = "1" Maximum = "400" Value = "1" 
         ValueChanged = "Slider_ValueChanged" />  
			
      <Ellipse Grid.Row = "1" Fill = "Aqua" Width = "1" x:Name = "myEllipse" /> 
		
   </Grid> 
	
</UserControl>

下面给出的是值已更改事件实现是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<double> e) { 
			
            if (myEllipse != null) { 
               myEllipse.Width = e.NewValue; 
            } 
      } 
   } 
}

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

添加滑块和椭圆