Pro Silverlight 3 in C# - XAML
3.1. XAML Basics
1 2 3 4 5 6 7 8 9 | <UserControl x:Class= "SilverlightApplication1.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> </UserControl> |
1 | 2. XAML Namespaces |
1 | 3. Design Namespaces |
1 | mc:Ignorable= "d" d:DesignWidth= "640" d:DesignHeight= "480" > |
1 | 4.Custom Namespaces |
1 | xmlns:w= "clr-namespace:Widgets" |
1 | <w:HotButton Text= "Click Me!" Click= "DoSomething" ></w:HotButton> |
1 | 5. Properties and Events in XAML |
1 |
1 2 3 4 5 6 7 8 9 10 11 12 | <Grid x:Name= "grid1" > <Grid.Background> <LinearGradientBrush> <LinearGradientBrush.GradientStops> <GradientStop Offset= "0.00" Color= "Yellow" /> <GradientStop Offset= "0.50" Color= "White" /> <GradientStop Offset= "1.00" Color= "Purple" /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Grid.Background> ... </Grid> |
-----------------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | LinearGradientBrush brush = new LinearGradientBrush(); GradientStop gradientStop1 = new GradientStop(); gradientStop1.Offset = 0; gradientStop1.Color = Colors.Yellow; brush.GradientStops.Add(gradientStop1); GradientStop gradientStop2 = new GradientStop(); gradientStop2.Offset = 0.5; gradientStop2.Color = Colors.White; brush.GradientStops.Add(gradientStop2); GradientStop gradientStop3 = new GradientStop(); gradientStop3.Offset = 1; gradientStop3.Color = Colors.Purple; brush.GradientStops.Add(gradientStop3); grid1.Background = brush; |
1 | |
1 | 6. Nesting Elements |
1 2 3 4 5 6 7 8 9 | <Grid x:Name= "grid1" > ... <TextBox x:Name= "txtQuestion" ... > </TextBox> <Button x:Name= "cmdAnswer" ... > </Button> <TextBox x:Name= "txtAnswer" ... > </TextBox> </Grid> |
-----------------------------------------------
1 2 3 4 5 6 7 8 9 | txtQuestion = new TextBox(); ... grid1.Children.Add(txtQuestion); cmdAnswer = new Button(); ... grid1.Children.Add(cmdAnswer); txtAnswer = new TextBox(); ... grid1.Children.Add(txtAnswer); |
------------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 | private void Clear(DependencyObject element) { // If this is a text box, clear the text. TextBox txt = element as TextBox; if (txt != null ) txt.Text = "" ; // Check for nested children. int children = VisualTreeHelper.GetChildrenCount(element); for ( int i = 0; i < children; i++) { DependencyObject child = VisualTreeHelper.GetChild(element, i); Clear(child); } } |
努力加载评论中...
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步