<Canvas x:Class="TgSilverlight.scene" 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="480" d:DesignWidth="640"> <Canvas.Resources> <!--如果是動態創建故事集 該段代碼可不要<Storyboard x:Name="BarRedrow"> <DoubleAnimation x:Name="BarRedrawDoubleAnimation" Storyboard.TargetName="Bar1" Storyboard.TargetProperty="Width" From="0" To="300" Duration="0:0:1" /> </Storyboard>--> </Canvas.Resources> <Canvas.Background> <LinearGradientBrush EndPoint="1.068,1.077" StartPoint="0.256,0.299"> <GradientStop Color="#ffffffff" Offset="0" /> <GradientStop Color="#fff2ff00" Offset="1" /> </LinearGradientBrush> </Canvas.Background> <Path Width="1" Height="400" Fill="#ffffffff" Stretch="Fill" Stroke="#ff000000" Canvas.Left="55" Canvas.Top="29.5" Data="M 50,50 50,400z"/> <Path Width="511" Height="1" Fill="#ffffffff" Stretch="Fill" Stroke="#ff000000" Canvas.Top="431.5" Canvas.Left="59.5" Data="M 50,400 450,400z" /> <TextBlock Width="31.334" Height="30.667" Canvas.Left="25.499" Canvas.Top="60" TextWrapping="Wrap" > <Run Text="Q1" /> </TextBlock> <TextBlock Width="31.334" Height="30.667" Canvas.Left="25.499" Canvas.Top="160" TextWrapping="Wrap" > <Run Text="Q2" /> </TextBlock> <TextBlock Width="31.334" Height="30.667" Canvas.Left="25.499" Canvas.Top="260" TextWrapping="Wrap" > <Run Text="Q3" /> </TextBlock> <TextBlock Width="31.334" Height="30.667" Canvas.Left="25.499" Canvas.Top="360" TextWrapping="Wrap" > <Run Text="Q4" /> </TextBlock> <TextBlock Width="31.334" Height="30.667" Canvas.Left="42.999" Canvas.Top="431.5" TextWrapping="Wrap" > <Run Text="0" /> </TextBlock> <TextBlock Width="31.334" Height="30.667" Canvas.Left="100" Canvas.Top="433.5" TextWrapping="Wrap" > <Run Text="100" /> </TextBlock> <TextBlock Width="31.334" Height="30.667" Canvas.Left="160" Canvas.Top="433.5" TextWrapping="Wrap" Text="200" /> <TextBlock Width="31.334" Height="30.667" Canvas.Left="220" Canvas.Top="433.5" TextWrapping="Wrap" Text="300" /> <TextBlock Width="31.334" Height="30.667" Canvas.Left="280" Canvas.Top="433.5" TextWrapping="Wrap" Text="400" /> <TextBlock Width="31.334" Height="30.667" Canvas.Left="340" Canvas.Top="433.5" TextWrapping="Wrap" Text="500" /> <TextBlock Width="31.334" Height="30.667" Canvas.Left="400" Canvas.Top="433.5" TextWrapping="Wrap" Text="600" /> <TextBlock Width="31.334" Height="30.667" Canvas.Left="460" Canvas.Top="433.5" TextWrapping="Wrap" Text="700" /> <TextBlock Width="31.334" Height="30.667" Canvas.Left="520" Canvas.Top="433.5" TextWrapping="Wrap" Text="800" /> <Rectangle x:Name="Bar1" Width="340" Height="40" Stroke="#ff979797" Canvas.Left="55.5" RenderTransformOrigin="0.5,0.5"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0.1,0.001"> <GradientStop Color="#fffffdfd" Offset="0" /> <GradientStop Color="#ff00ff11" Offset="1" /> </LinearGradientBrush> </Rectangle.Fill> <Rectangle.RenderTransform> <TransformGroup> <!--縮放變形 其值表示縮放的比例--> <ScaleTransform ScaleX="-1" ScaleY="1" /> <!--產生基於 X Y的偏移三維效果--> <SkewTransform AngleX="0" AngleY="0"/> <!--旋轉變形Angle表示旋轉的角度--> <RotateTransform Angle="0" /> <!--平移變形--> <TranslateTransform X="0" Y="50" /> </TransformGroup> </Rectangle.RenderTransform> </Rectangle> <Rectangle x:Name="Bar2" Width="340" Height="40" Stroke="#ff979797" Canvas.Left="55.5" RenderTransformOrigin="0.5,0.5"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0.1,0.001"> <GradientStop Color="#fffffdfd" Offset="0" /> <GradientStop Color="#ff00ff11" Offset="1" /> </LinearGradientBrush> </Rectangle.Fill> <Rectangle.RenderTransform> <TransformGroup> <ScaleTransform ScaleX="-1" ScaleY="1" /> <SkewTransform AngleX="0" AngleY="0"/> <RotateTransform Angle="0" /> <TranslateTransform X="0" Y="150" /> </TransformGroup> </Rectangle.RenderTransform> </Rectangle> <Rectangle x:Name="Bar3" Width="340" Height="40" Stroke="#ff979797" Canvas.Left="55.5" RenderTransformOrigin="0.5,0.5"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0.1,0.001"> <GradientStop Color="#fffffdfd" Offset="0" /> <GradientStop Color="#ff00ff11" Offset="1" /> </LinearGradientBrush> </Rectangle.Fill> <Rectangle.RenderTransform> <TransformGroup> <ScaleTransform ScaleX="-1" ScaleY="1" /> <SkewTransform AngleX="0" AngleY="0"/> <RotateTransform Angle="0" /> <TranslateTransform X="0" Y="250" /> </TransformGroup> </Rectangle.RenderTransform> </Rectangle> <Rectangle x:Name="Bar4" Width="340" Height="40" Stroke="#ff979797" Canvas.Left="55.5" RenderTransformOrigin="0.5,0.5"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0.1,0.001"> <GradientStop Color="#fffffdfd" Offset="0" /> <GradientStop Color="#ff00ff11" Offset="1" /> </LinearGradientBrush> </Rectangle.Fill> <Rectangle.RenderTransform> <TransformGroup> <ScaleTransform ScaleX="-1" ScaleY="1" /> <SkewTransform AngleX="0" AngleY="0"/> <RotateTransform Angle="0" /> <TranslateTransform X="0" Y="350" /> </TransformGroup> </Rectangle.RenderTransform> </Rectangle> </Canvas>
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; using System.Windows.Browser; using System.Windows.Markup; namespace TgSilverlight { public partial class scene : Canvas { public scene() { InitializeComponent(); //獲取頁面的button對象 HtmlElement button = HtmlPage.Document.GetElementById("btnShow"); //註冊button的click事件 button.AttachEvent("onclick",new EventHandler<HtmlEventArgs>(button_onClick)); HtmlPage.RegisterScriptableObject("Builder",this); } public void button_onClick(object sender, HtmlEventArgs e) { HtmlElement txtYear = HtmlPage.Document.GetElementById("txtYear"); string value = txtYear.GetAttribute("value"); if (value.Equals("2006")) { ShowAnima(date2006); } else { ShowAnima(date2007); } } int[] date2006 = { 100, 200, 300, 400 }; //四個矩形寬度值 int[] date2007 = { 200, 100, 250, 200 }; [ScriptableMember] public void JsShowAnima(string a, int i) //調用後有小bug 前三個矩形寬度不能保存(待解決) { BarRedrow.Stop(); int[] val = a == "2006" ? date2006 : date2007; BarRedrawDoubleAnimation.From = 0; BarRedrawDoubleAnimation.SetValue(Storyboard.TargetNameProperty, "Bar" + i.ToString()); BarRedrawDoubleAnimation.SetValue(Storyboard.DurationProperty, new Duration(new TimeSpan(0, 0, 2))); BarRedrawDoubleAnimation.To = val[i - 1]; BarRedrow.Begin(); } public void ShowAnima(int [] val) { for (int k = 1; k <= 4; k++) { this.Resources.Remove("story" + k.ToString()); } for (int i = 1; i <= 4; i++) { Storyboard story = new Storyboard(); //創建4個Storyboard故事集用於顯示4個Rectangle動畫 DoubleAnimation anima = new DoubleAnimation(); anima.From = 0; anima.SetValue(Storyboard.TargetNameProperty, "Bar" + i.ToString()); anima.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("Width")); anima.SetValue(Storyboard.DurationProperty, new Duration(new TimeSpan(0, 0, i))); anima.To = val[i - 1]; story.Children.Add(anima); this.Resources.Add("story" + i.ToString(), story); story.Begin(); } } } }
<%@ Page Language="C#" AutoEventWireup="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>TgSilverlight</title> <mce:style type="text/css"><!-- html, body { height: 100%; overflow: auto; } body { padding: 0; margin: 0; } #silverlightControlHost { height: 100%; text-align:center; } --></mce:style><style type="text/css" mce_bogus="1"> html, body { height: 100%; overflow: auto; } body { padding: 0; margin: 0; } #silverlightControlHost { height: 100%; text-align:center; } </style> <mce:script type="text/javascript" src="Silverlight.js" mce_src="Silverlight.js"></mce:script> <mce:script type="text/javascript"><!-- function onSilverlightError(sender, args) { var appSource = ""; if (sender != null && sender != 0) { appSource = sender.getHost().Source; } var errorType = args.ErrorType; var iErrorCode = args.ErrorCode; if (errorType == "ImageError" || errorType == "MediaError") { return; } var errMsg = "Silverlight 應用程序中未處理的錯誤 " + appSource + "/n" ; errMsg += "代碼: "+ iErrorCode + " /n"; errMsg += "類別: " + errorType + " /n"; errMsg += "消息: " + args.ErrorMessage + " /n"; if (errorType == "ParserError") { errMsg += "文件: " + args.xamlFile + " /n"; errMsg += "行: " + args.lineNumber + " /n"; errMsg += "位置: " + args.charPosition + " /n"; } else if (errorType == "RuntimeError") { if (args.lineNumber != 0) { errMsg += "行: " + args.lineNumber + " /n"; errMsg += "位置: " + args.charPosition + " /n"; } errMsg += "方法名稱: " + args.methodName + " /n"; } 引發新錯誤(errMsg); } // --></mce:script> <mce:script type="text/javascript"><!-- function ShowSilverlight() { var i = 1; var xamlObj = document.all("xamlObj"); setTimeout(function () { xamlObj.content.Builder.JsShowAnima(document.getElementById("txtYear").value, i++); }, 0); setTimeout(function () { xamlObj.content.Builder.JsShowAnima(document.getElementById("txtYear").value, i++); }, 2000); setTimeout(function () { xamlObj.content.Builder.JsShowAnima(document.getElementById("txtYear").value, i++); }, 4000); setTimeout(function () { xamlObj.content.Builder.JsShowAnima(document.getElementById("txtYear").value, i++); }, 6000); } // --></mce:script> </head> <body> <form id="form1" runat="server" style="height:100%"> <div id="silverlightControlHost" style="width:640px;height:480px;"> <object id="xamlObj" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="source" value="ClientBin/TgSilverlight.xap"/> <param name="onError" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="4.0.50826.0" /> <param name="autoUpgrade" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" mce_href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none" mce_style="text-decoration:none"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" mce_src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="獲取 Microsoft Silverlight" style="border-style:none" mce_style="border-style:none"/> </a> </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div> <br /> 請輸入年份:<input type="text" id="txtYear" /> <input id="btnShow" type="button" value="通過Silverlight調用" style="width:140px;" /> <input onclick="ShowSilverlight()" type="button" value="通過JS調用Silverlight函數" style="width:180px;" /> </form> </body> </html>
silverlight作爲微軟在.net領域的又一力作,自推出以來就備受關注,個人認爲它有如下一些優劣勢: 優勢: UI設計和代碼分離。這下開發人員不用擔心界面變來變去了,UI設計人員直接設計好了就可供開發實用,也就是說如果公司有專職UI
http://apps.hi.baidu.com/share/detail/30790580 微軟的幫助真是強大啊,大多數的東西拾人牙慧居多,看原版: http://msdn.microsoft.com/zh-cn/library/ee7
1.遍歷DataGrid的方法 //--需要遍歷的列 var selfcols = dgExContent.Columns[2]; foreach (var item in dataGrid1.ItemsSource) { //--數
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries>
創建Cookie DateTime expries=DateTime.UtcNow+TimeSpan.FromDays(15); //設置保存有效天數 string cookie=string.Format("{0}={1}
服務端:C# + MS SQL Server 2005/2008客戶端:Silverlight控件DataPager+DevExpress控件AgDataGrid第一步:統計頁數Select COUNT(ID) from Table第二步
在IIS上新建一個網站,然後對網站進行配置 1.註冊擴展名 右鍵網站---->屬性----->Http頭---->MIME類型----->新建 擴展名:.xap MIME類型:applic
Working with source Checkout Source CodeThe source code of white is not hosted on Codeplex since 0.18 onwards. Its av
ItemsControl: 'L' is for Lookless (a.k.a., "Styles, Templates, andTriggers… Oh My!")在這片文章中,我們將研究WPF控件如何通過樣式和模板獲取可視化展示。然
學習SilverLight(五)
學習SilverLight(八)
功能描述: ComboBox+TreeView實現的用戶控件,設置數據源後,可以遞歸加載數據,支持雙向綁定 控件截圖: XAML界面設計: <UserControl x:Class="ChuanyeOA.Custom
網站如果應用了Silverlight技術,直接部署到IIS中是無法正常運行的,因爲Silverlight應用所對應的三種MIME類型沒 有在IIS中註冊,所以Silverlight相關的文件無法下載到客戶端,而Silverlig
還有一個形狀不應該忘記:橢圓,使用<Ellipse>元素表現。最重要的屬性是Width和Height,用來決定了橢圓的尺寸。例4-9顯示了一個橢圓,圖4-8是它在瀏覽器中的輸出效果。 圖4-7 橢圓 提示:當橢圓的寬度和高度相同
使用圖像 雖然Silverlight是基於矢量的技術,但它也支持像素圖像。XAML的<Image>元素用於處理圖像。除了默認的屬性如Canvas.Left,Canvas.Top,Height和Width,<Image>還需要知道要顯示哪張