自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

淺析Silverlight中ViewBox組件

開發(fā) 后端
這里我們將介紹Silverlight中ViewBox組件,本文將為大家介紹該組件的基本特性以及應(yīng)用實例。

這里我們將介紹Silverlight中ViewBox組件,這個組件的作用主要是做布局與視覺效果。并給出實例代碼和最終效果圖。

ViewBox組件的作用是拉伸或延展位于其中的組件,使之有更好的布局及視覺效果。本文將為大家介紹該組件的基本特性以及應(yīng)用實例。

組件所在命名空間:

System.Windows.Controls

組件常用屬性:

Child:獲取或設(shè)置一個ViewBox元素的單一子元素。

Stretch:獲取或設(shè)置拉伸模式以決定該組件中的內(nèi)容以怎樣的形式填充該組件的已有空間。

StretchDirection:獲取或設(shè)置該組件的拉伸方向以決定該組件中的內(nèi)容將以何種形式被延展。

實例:

詳細的說明在代碼注釋中給出。

MainPage.xaml文件代碼:

  1. <UserControl 
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
  5. mc:Ignorable="d" xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" x:Class="SilverlightClient.MainPage" 
  6. d:DesignWidth="320" d:DesignHeight="240"> 
  7. <Grid x:Name="LayoutRoot" Width="320" Height="240" Background="White"> 
  8. <Slider x:Name="HSlider" Minimum="0" Maximum="100"  Height="24" Margin="79,0,91,42" VerticalAlignment="Bottom" Width="150"/> 
  9. <Slider x:Name="VSlider" Minimum="0" Maximum="100" HorizontalAlignment="Right" Margin="0,24,57,66" Width="30" Orientation="Vertical" Height="150"/> 
  10. <Border Margin="79,24,91,66" BorderBrush="Black" BorderThickness="1"> 
  11. <Grid x:Name="theContainer" Background="AntiqueWhite"> 
  12. <controlsToolkit:Viewbox x:Name="sampleViewBox" Margin="0,0,-2,-2"> 
  13. <!--放入ViewBox中的按鈕對象--> 
  14. <Button Width="101" Content="Button"/> 
  15. </controlsToolkit:Viewbox> 
  16. </Grid> 
  17. </Border> 
  18. <ComboBox x:Name="cbStretch" Height="21" HorizontalAlignment="Left" Margin="8,0,0,8" VerticalAlignment="Bottom" Width="139"/> 
  19. <ComboBox x:Name="cbStretchDirection" Height="21" HorizontalAlignment="Right" Margin="0,0,8,8" VerticalAlignment="Bottom" Width="139"/> 
  20. <TextBlock Height="16" HorizontalAlignment="Left" Margin="9,0,0,33" VerticalAlignment="Bottom" Width="66" Text="拉伸模式:" TextWrapping="Wrap"/> 
  21. <TextBlock Height="16" HorizontalAlignment="Right" Margin="0,0,8,33" VerticalAlignment="Bottom" Width="56" Text="拉伸方向:" TextWrapping="Wrap"/> 
  22. </Grid> 
  23. </UserControl> 

MainPage.xaml.cs文件代碼:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Documents;  
  8. using System.Windows.Input;  
  9. using System.Windows.Media;  
  10. using System.Windows.Media.Animation;  
  11. using System.Windows.Shapes;  
  12. namespace SilverlightClient  
  13. {  
  14. //輔助類StretchHelper  
  15. public class StretchHelper  
  16. {  
  17. public string StretchModeName { get; set; }  
  18. public Stretch theStretchMode { get; set; }  
  19. }  
  20. //輔助類StretchDirectionHelper  
  21. public class StretchDirectionHelper  
  22. {  
  23. public string StretchDirectionName { get; set; }  
  24. public StretchDirection theStretchDirection { get; set; }  
  25. }  
  26. public partial class MainPage : UserControl  
  27. {  
  28. //定義cbStretch與cbStretchDirection的數(shù)據(jù)源  
  29. List<StretchHelper> cbStretchList = new List<StretchHelper>();  
  30. List<StretchDirectionHelper> cbStretchDirectionList = new List<StretchDirectionHelper>();  
  31. public MainPage()  
  32. {  
  33. InitializeComponent();  
  34. //注冊事件觸發(fā)  
  35. this.Loaded += new RoutedEventHandler(MainPage_Loaded);  
  36. this.cbStretch.SelectionChanged += new SelectionChangedEventHandler(cbStretch_SelectionChanged);  
  37. this.cbStretchDirection.SelectionChanged += new SelectionChangedEventHandler(cbStretchDirection_SelectionChanged);  
  38. this.HSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(HSlider_ValueChanged);  
  39. this.VSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(VSlider_ValueChanged);  
  40. }  
  41. void VSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)  
  42. {  
  43. sampleViewBox.Height = theContainer.ActualHeight * VSlider.Value / 100.0;  
  44. }  
  45. void HSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)  
  46. {  
  47. sampleViewBox.Width = theContainer.ActualWidth * HSlider.Value / 100.0;  
  48. }  
  49. void cbStretchDirection_SelectionChanged(object sender, SelectionChangedEventArgs e)  
  50. {  
  51. if (cbStretchDirection.SelectedItem != null)  
  52. {  
  53. sampleViewBox.StretchDirection = (cbStretchDirection.SelectedItem as StretchDirectionHelper).theStretchDirection;  
  54. }  
  55. }  
  56. void cbStretch_SelectionChanged(object sender, SelectionChangedEventArgs e)  
  57. {  
  58. if (cbStretch.SelectedItem != null)  
  59. {  
  60. sampleViewBox.Stretch = (cbStretch.SelectedItem as StretchHelper).theStretchMode;  
  61. }  
  62. }  
  63. void MainPage_Loaded(object sender, RoutedEventArgs e)  
  64. {  
  65. //填充各ComboBox內(nèi)容  
  66. cbStretchList.Add(new StretchHelper() { StretchModeName = "Fill"theStretchMode = Stretch.Fill });  
  67. cbStretchList.Add(new StretchHelper() { StretchModeName = "None"theStretchMode = Stretch.None });  
  68. cbStretchList.Add(new StretchHelper() { StretchModeName = "Uniform"theStretchMode = Stretch.Uniform });  
  69. cbStretchList.Add(new StretchHelper() { StretchModeName = "UniformToFill"theStretchMode = Stretch.UniformToFill });  
  70. cbStretch.ItemsSource = cbStretchList;  
  71. cbStretch.DisplayMemberPath = "StretchModeName";  
  72. cbStretchDirectionList.Add(new StretchDirectionHelper() { StretchDirectionName = "DownOnly"theStretchDirection = StretchDirection.DownOnly });  
  73. cbStretchDirectionList.Add(new StretchDirectionHelper() { StretchDirectionName = "UpOnly"theStretchDirection = StretchDirection.UpOnly });  
  74. cbStretchDirectionList.Add(new StretchDirectionHelper() { StretchDirectionName = "Both"theStretchDirection = StretchDirection.Both });  
  75. cbStretchDirection.ItemsSource = cbStretchDirectionList;  
  76. cbStretchDirection.DisplayMemberPath = "StretchDirectionName";  
  77. }  
  78. }  

最終效果圖:

最終效果圖 

本文來自Kinglee博客園文章《有關(guān)ViewBox組件的研究——Silverlight學習筆記[34]

【編輯推薦】

  1. Office 2010將使用Silverlight改善用戶體驗
  2. 微軟.NET平臺主管談Silverlight企業(yè)級開發(fā)
  3. Flash與Silverlight多領(lǐng)域?qū)崪y對比
  4. 微軟宣稱Silverlight裝機量超過三億
  5. 圖解Silverlight 3的7個新功能
責任編輯:彭凡 來源: 博客園
相關(guān)推薦

2009-11-26 13:12:16

Silverlight

2009-04-03 13:09:12

Windows Emb

2009-09-27 13:38:03

Silverlight

2009-09-28 10:35:45

Silverlight

2009-11-17 10:47:14

Silverlight

2011-12-29 15:35:39

Web

2011-12-30 09:49:36

Silverlight

2009-12-29 16:36:47

Silverlight

2009-09-22 18:39:02

Silverlight

2009-12-31 17:31:23

Silverlight

2009-12-31 16:50:02

Silverlight

2009-07-15 11:02:32

Swing組件

2009-08-05 16:53:14

ASP.NET組件設(shè)計

2009-09-17 16:41:12

C#組件編程

2009-11-13 10:10:07

2024-01-09 09:06:13

2022-05-10 07:46:08

Envoy網(wǎng)絡(luò)通訊

2009-12-30 16:37:42

Silverlight

2009-02-20 08:54:20

DownloaderSilverlight對象

2009-06-03 10:24:11

LoadMaskSilverlight
點贊
收藏

51CTO技術(shù)棧公眾號