Silverlight中ViewBox組件如何使用

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)Silverlight中ViewBox組件如何使用,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

我們提供的服務(wù)有:網(wǎng)站建設(shè)、做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、洋縣ssl等。為超過千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的洋縣網(wǎng)站制作公司

組件所在命名空間:

System.Windows.Controls

組件常用屬性:

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

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

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

實例:

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

MainPage.xaml文件代碼:

<UserControl 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" xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" x:Class="SilverlightClient.MainPage" d:DesignWidth="320" d:DesignHeight="240"> <Grid x:Name="LayoutRoot" Width="320" Height="240" Background="White"> <Slider x:Name="HSlider" Minimum="0" Maximum="100"  Height="24" Margin="79,0,91,42" VerticalAlignment="Bottom" Width="150"/> <Slider x:Name="VSlider" Minimum="0" Maximum="100" HorizontalAlignment="Right" Margin="0,24,57,66" Width="30" Orientation="Vertical" Height="150"/> <Border Margin="79,24,91,66" BorderBrush="Black" BorderThickness="1"> <Grid x:Name="theContainer" Background="AntiqueWhite"> <controlsToolkit:Viewbox x:Name="sampleViewBox" Margin="0,0,-2,-2"> <!--放入ViewBox中的按鈕對象--> <Button Width="101" Content="Button"/> </controlsToolkit:Viewbox> </Grid> </Border> <ComboBox x:Name="cbStretch" Height="21" HorizontalAlignment="Left" Margin="8,0,0,8" VerticalAlignment="Bottom" Width="139"/> <ComboBox x:Name="cbStretchDirection" Height="21" HorizontalAlignment="Right" Margin="0,0,8,8" VerticalAlignment="Bottom" Width="139"/> <TextBlock Height="16" HorizontalAlignment="Left" Margin="9,0,0,33" VerticalAlignment="Bottom" Width="66" Text="拉伸模式:" TextWrapping="Wrap"/> <TextBlock Height="16" HorizontalAlignment="Right" Margin="0,0,8,33" VerticalAlignment="Bottom" Width="56" Text="拉伸方向:" TextWrapping="Wrap"/> </Grid> </UserControl>

MainPage.xaml.cs文件代碼:

using System;  using System.Collections.Generic;  using System.Linq;  using System.Net;  using System.Windows;  using System.Windows.Controls;  using System.Windows.Documents;  using System.Windows.Input;  using System.Windows.Media;  using System.Windows.Media.Animation;  using System.Windows.Shapes;  namespace SilverlightClient  {  //輔助類StretchHelper  public class StretchHelper  {  public string StretchModeName { get; set; }  public Stretch theStretchMode { get; set; }  }  //輔助類StretchDirectionHelper  public class StretchDirectionHelper  {  public string StretchDirectionName { get; set; }  public StretchDirection theStretchDirection { get; set; }  }  public partial class MainPage : UserControl  {  //定義cbStretch與cbStretchDirection的數(shù)據(jù)源  List<StretchHelper> cbStretchList = new List<StretchHelper>();  List<StretchDirectionHelper> cbStretchDirectionList = new List<StretchDirectionHelper>();  public MainPage()  {  InitializeComponent();  //注冊事件觸發(fā)  this.Loaded += new RoutedEventHandler(MainPage_Loaded);  this.cbStretch.SelectionChanged += new SelectionChangedEventHandler(cbStretch_SelectionChanged);  this.cbStretchDirection.SelectionChanged += new SelectionChangedEventHandler(cbStretchDirection_SelectionChanged);  this.HSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(HSlider_ValueChanged);  this.VSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(VSlider_ValueChanged);  }  void VSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)  {  sampleViewBox.Height = theContainer.ActualHeight * VSlider.Value / 100.0;  }  void HSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)  {  sampleViewBox.Width = theContainer.ActualWidth * HSlider.Value / 100.0;  }  void cbStretchDirection_SelectionChanged(object sender, SelectionChangedEventArgs e)  {  if (cbStretchDirection.SelectedItem != null)  {  sampleViewBox.StretchDirection = (cbStretchDirection.SelectedItem as StretchDirectionHelper).theStretchDirection;  }  }  void cbStretch_SelectionChanged(object sender, SelectionChangedEventArgs e)  {  if (cbStretch.SelectedItem != null)  {  sampleViewBox.Stretch = (cbStretch.SelectedItem as StretchHelper).theStretchMode;  }  }  void MainPage_Loaded(object sender, RoutedEventArgs e)  {  //填充各ComboBox內(nèi)容  cbStretchList.Add(new StretchHelper() { StretchModeName = "Fill", theStretchMode = Stretch.Fill });  cbStretchList.Add(new StretchHelper() { StretchModeName = "None", theStretchMode = Stretch.None });  cbStretchList.Add(new StretchHelper() { StretchModeName = "Uniform", theStretchMode = Stretch.Uniform });  cbStretchList.Add(new StretchHelper() { StretchModeName = "UniformToFill", theStretchMode = Stretch.UniformToFill });  cbStretch.ItemsSource = cbStretchList;  cbStretch.DisplayMemberPath = "StretchModeName";  cbStretchDirectionList.Add(new StretchDirectionHelper() { StretchDirectionName = "DownOnly", theStretchDirection = StretchDirection.DownOnly });  cbStretchDirectionList.Add(new StretchDirectionHelper() { StretchDirectionName = "UpOnly", theStretchDirection = StretchDirection.UpOnly });  cbStretchDirectionList.Add(new StretchDirectionHelper() { StretchDirectionName = "Both", theStretchDirection = StretchDirection.Both });  cbStretchDirection.ItemsSource = cbStretchDirectionList;  cbStretchDirection.DisplayMemberPath = "StretchDirectionName";  }  }  }

最終效果圖:

Silverlight中ViewBox組件如何使用 

上述就是小編為大家分享的Silverlight中ViewBox組件如何使用了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

文章名稱:Silverlight中ViewBox組件如何使用
文章路徑:http://muchs.cn/article0/gdcgio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站微信小程序、用戶體驗、網(wǎng)站改版、Google、網(wǎng)站設(shè)計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)