日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
淺析Silverlight中ViewBox組件

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

創(chuàng)新互聯(lián)是一家以網(wǎng)絡(luò)技術(shù)公司,為中小企業(yè)提供網(wǎng)站維護(hù)、成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、網(wǎng)站備案、服務(wù)器租用、域名注冊、軟件開發(fā)、微信小程序開發(fā)等企業(yè)互聯(lián)網(wǎng)相關(guān)業(yè)務(wù),是一家有著豐富的互聯(lián)網(wǎng)運(yùn)營推廣經(jīng)驗(yàn)的科技公司,有著多年的網(wǎng)站建站經(jīng)驗(yàn),致力于幫助中小企業(yè)在互聯(lián)網(wǎng)讓打出自已的品牌和口碑,讓企業(yè)在互聯(lián)網(wǎng)上打開一個(gè)面向全國乃至全球的業(yè)務(wù)窗口:建站來電聯(lián)系:18980820575

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

組件所在命名空間:

System.Windows.Controls

組件常用屬性:

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

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

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

實(shí)例:

詳細(xì)的說明在代碼注釋中給出。

MainPage.xaml文件代碼:

 
 
 
 
  1.  
  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.  x:Name="LayoutRoot" Width="320" Height="240" Background="White"> 
  8.  x:Name="HSlider" Minimum="0" Maximum="100"  Height="24" Margin="79,0,91,42" VerticalAlignment="Bottom" Width="150"/> 
  9.  x:Name="VSlider" Minimum="0" Maximum="100" HorizontalAlignment="Right" Margin="0,24,57,66" Width="30" Orientation="Vertical" Height="150"/> 
  10.  Margin="79,24,91,66" BorderBrush="Black" BorderThickness="1"> 
  11.  x:Name="theContainer" Background="AntiqueWhite"> 
  12.  x:Name="sampleViewBox" Margin="0,0,-2,-2"> 
  13.  
  14.  Width="101" Content="Button"/> 
  15.  
  16.  
  17.  
  18.  x:Name="cbStretch" Height="21" HorizontalAlignment="Left" Margin="8,0,0,8" VerticalAlignment="Bottom" Width="139"/> 
  19.  x:Name="cbStretchDirection" Height="21" HorizontalAlignment="Right" Margin="0,0,8,8" VerticalAlignment="Bottom" Width="139"/> 
  20.  Height="16" HorizontalAlignment="Left" Margin="9,0,0,33" VerticalAlignment="Bottom" Width="66" Text="拉伸模式:" TextWrapping="Wrap"/> 
  21.  Height="16" HorizontalAlignment="Right" Margin="0,0,8,33" VerticalAlignment="Bottom" Width="56" Text="拉伸方向:" TextWrapping="Wrap"/> 
  22.  
  23.  

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 cbStretchList = new List();  
  30. List cbStretchDirectionList = new List();  
  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(HSlider_ValueChanged);  
  39. this.VSlider.ValueChanged += new RoutedPropertyChangedEventHandler(VSlider_ValueChanged);  
  40. }  
  41. void VSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)  
  42. {  
  43. sampleViewBox.Height = theContainer.ActualHeight * VSlider.Value / 100.0;  
  44. }  
  45. void HSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs 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學(xué)習(xí)筆記[34]

【編輯推薦】

  1. Office 2010將使用Silverlight改善用戶體驗(yàn)
  2. 微軟.NET平臺主管談Silverlight企業(yè)級開發(fā)
  3. Flash與Silverlight多領(lǐng)域?qū)崪y對比
  4. 微軟宣稱Silverlight裝機(jī)量超過三億
  5. 圖解Silverlight 3的7個(gè)新功能

網(wǎng)站題目:淺析Silverlight中ViewBox組件
文章位置:http://www.dlmjj.cn/article/djdpejd.html