Metro Style App开发快速入门 之基本控件使用总结

简介:

最近在研究Metro style App的控件使用, 下面我简单介绍下Metro style App的一些基本控件的使用方法。以后的我会介绍其他控件的使用。

运行环境请参考:Metro Style App之文件访问操作示例。当然控件使用最好自己操作一下比较好。

1、ProgressRing控件

<ProgressRing HorizontalAlignment= "Left"  Height= "20"  Margin= "38,43,0,0"  IsActive= "{Binding IsChecked,ElementName=IsActiveCBX}"  VerticalAlignment= "Top"  Width= "55" />
<CheckBox x:Name= "IsActiveCBX"  IsChecked= "True"  Content= "CheckBox"  HorizontalAlignment= "Left"  Height= "22"  Margin= "63,103,0,0"  VerticalAlignment= "Top"  Width= "17"  RenderTransformOrigin= "1.05900001525879,1.1599999666214" />

效果图:

 

2、进度条ProgressBar

<ProgressBar HorizontalAlignment= "Left"  Maximum= "100"  IsIndeterminate= "{Binding IsChecked,ElementName=CB1}"
                       ShowPaused= "{Binding IsChecked,ElementName=CB2}"  ShowError= "{Binding IsChecked,ElementName=CB3}"
                      Value= "{Binding Text,ElementName=Value, Converter={StaticResource StringToDoubleConverter}}"   Margin= "169,43,0,0"  VerticalAlignment= "Top"  Width= "100" />
<TextBox x:Name= "Value"  Width= "80"  Height= "30"  Margin= "169,71,1117,665" />
<CheckBox x:Name= "CB1"  Content= "IsIndeterminate"  HorizontalAlignment= "Left"  Margin= "169,108,0,0"  VerticalAlignment= "Top" />
<CheckBox x:Name= "CB2"  Content= "ShowPaused"  HorizontalAlignment= "Left"  Height= "19"  Margin= "169,158,0,0"  VerticalAlignment= "Top"  Width= "155" />
<CheckBox x:Name= "CB3"  Content= "SHowError"  HorizontalAlignment= "Left"  Height= "14"  Margin= "169,208,0,0"  VerticalAlignment= "Top"  Width= "119" />

 

3、ToggleSwitch控件,OnContent,OffContent也可以采用Binding的形式。ToggleSwitch控件就像一个开关。

<ToggleSwitch Header= "Head Content"  OnContent= "On Content"  OffContent= "Off Content"  HorizontalAlignment= "Left"  Height= "54"  Margin= "324,49,0,0"  VerticalAlignment= "Top"  Width= "98" />


4、CheckBox控件。IsHitTestVisible鼠标单击时,CheckBox无效。IsTabStop属性:当按Tabl时,直接跳到下一个。

<CheckBox x:Name= "IsChecked"  IsHitTestVisible= "False"  IsTabStop= "False"   Content= "IsChecked "  Margin= "10,0,0,0"  VerticalAlignment= "Center"
                    IsChecked= "{Binding IsChecked, ElementName=CheckBox1}" />

5、ComboBox控件。

<ComboBox HorizontalAlignment= "Left"  Margin= "324,126,0,0"  VerticalAlignment= "Top"  Width= "120"  SelectionChanged= "ComboBox_SelectionChanged"  SelectedIndex= "0" >
             <TextBlock>Item1</TextBlock>
             <TextBlock>Item2</TextBlock>
             <TextBlock>Item3</TextBlock>
             <TextBlock>Item4</TextBlock>
</ComboBox>

 获得选中的Item值。

private  void  ComboBox_SelectionChanged( object  sender, SelectionChangedEventArgs e)
{
       string  selectItem = ((TextBlock)e.AddedItems[0]).Text;
  }

 

6、Image控件。

ToolTipService.ToolTip="Oregon Coast", ToolTipService.Placement="Right" 这两个属性表示鼠标移动到图片时显示的文本以及文本位置。

<Image x:Name= "Image1"  Source= "images/image1.jpg"  Width= "200"  Height= "100"  Stretch= "UniformToFill"  Margin= "5"  ToolTipService.ToolTip= "Oregon Coast"  ToolTipService.Placement= "Right" />

 

 7、Popup控件。

当单击Button时,显示Popub控件,再次单击Button时,则隐藏Popup控件。

Popup popup = new  Popup();
bool  bShowPopup = false ;
private  void  PopupButton_Click( object  sender, RoutedEventArgs e)
{
     bShowPopup = !bShowPopup;
     if  (bShowPopup)
     {
         PopupButton.Content = "Hide Popub" ;
         popup.Child = new  PopuPanelControl();
         popup.VerticalOffset = 500;
         popup.HorizontalOffset = 100;
         popup.IsOpen = true ;
     }
     else
     {
         PopupButton.Content = "Show Popup" ;
         popup.IsOpen = false ;
     }
}

 下面是自定义的Popup控件。当然可以根据自己的喜好来定义。

<UserControl
     x:Class= "BasicHandle.BasicControl.PopuPanelControl"
     xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:local= "using:BasicHandle.BasicControl"
     xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
     mc:Ignorable= "d"  d:DesignHeight= "300"  d:DesignWidth= "400" >
     <Border BorderBrush= "#19000000"  BorderThickness= "1"  Background= "White" >
         <Grid>
             <TextBlock HorizontalAlignment= "Left"  Foreground= "Black"  Margin= "35,69,0,0"  TextWrapping= "Wrap"  Text= "This is Popup Panel Control"  VerticalAlignment= "Top"  Height= "97"  Width= "181" />
         </Grid>
     </Border>
</UserControl>

 

7、自定义Button控件。

VisualStateManager.VisualStateGroups用来管理控件母板的显示效果的。

<Style x:Key= "CustomButtonStyle"  TargetType= "Button" >
             <Setter Property= "Background"  Value= "Orange" />
             <Setter Property= "Foreground"  Value= "Black" />
             <Setter Property= "FontFamily"  Value= "Comic Sans MS" />
             <Setter Property= "FontSize"  Value= "30" />
             <Setter Property= "Template" >
                 <Setter.Value>
                     <ControlTemplate TargetType= "Button" >
                         <Grid>
                             <VisualStateManager.VisualStateGroups>
                                 <VisualStateGroup x:Name= "CommonStates" >
                                     <VisualState x:Name= "Normal" />
                                     <VisualState x:Name= "PointerOver" >
                                         <Storyboard>
                                             <ColorAnimation Duration= "0"  To= "Red"  Storyboard.TargetProperty= "(Rectangle.Fill).(SolidColorBrush.Color)"  Storyboard.TargetName= "Border"  />
                                         </Storyboard>
                                     </VisualState>
                                     <VisualState x:Name= "Pressed" >
                                         <Storyboard>
                                             <ColorAnimation Duration= "0"  To= "Black"  Storyboard.TargetProperty= "(Rectangle.Fill).(SolidColorBrush.Color)"  Storyboard.TargetName= "Border"  />
                                             <ColorAnimation Duration= "0"  To= "White"  Storyboard.TargetProperty= "(TextBlock.Foreground).(SolidColorBrush.Color)"  Storyboard.TargetName= "Content"  />
                                         </Storyboard>
                                     </VisualState>
                                 </VisualStateGroup>
                             </VisualStateManager.VisualStateGroups>
                             <Grid>
                                 <Rectangle x:Name= "Border"  Stroke= "Black"  Fill= "Orange"  Margin= "-5" />
                                 <ContentPresenter x:Name= "Content" />
                             </Grid>
                         </Grid>
                     </ControlTemplate>
                 </Setter.Value>
             </Setter>
         </Style>

  如下图:当鼠标移动到控件时显示红色。

 需要特别注意的是:Metro Style App采用Visual State。之前的触发器已经没有了。当然在这里我只是介绍Metro Style App控件的一些简单的用法,Metro Style App的Visual Manager不在此处介绍。


总结:Metro Style App的基本控件基本跟以前一样,改变比较大的事触发器没了,代之的是Visual State。

以上只是自己的一点学习心得,如果有什么意见和建议,欢迎大家提出!当然自己还在学习研究中,希望与大家共同学习,一起进步!

 


本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2012/03/15/2398338.html,如需转载请自行联系原作者

目录
相关文章
|
1月前
|
缓存 移动开发 JavaScript
如何优化UniApp开发的App的启动速度?
如何优化UniApp开发的App的启动速度?
386 139
|
1月前
|
移动开发 JavaScript weex
UniApp开发的App在启动速度方面有哪些优势和劣势?
UniApp开发的App在启动速度方面有哪些优势和劣势?
292 137
|
1月前
|
移动开发 JavaScript 应用服务中间件
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
198 5
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
1月前
|
移动开发 前端开发 Android开发
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
233 12
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
1月前
|
移动开发 Rust JavaScript
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
506 4
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
1月前
|
人工智能 前端开发 JavaScript
最佳实践3:用通义灵码开发一款 App
本示例演示使用通义灵码,基于React Native与Node.js开发跨平台类通义App,重点展示iOS端实现。涵盖前端页面生成、后端代码库自动生成、RTK Query通信集成及Qwen API调用全过程,体现灵码在全栈开发中的高效能力。(238字)
232 11
|
1月前
|
人工智能 小程序 开发者
【一步步开发AI运动APP】十二、自定义扩展新运动项目03
继【一步步开发AI运动小程序】后,我们推出新系列【一步步开发AI运动APP】,助开发者打造高性能、优体验的AI运动应用。本文详解自定义扩展运动分析器的统一管理实现,提升代码复用性与可维护性,涵盖APP与小程序插件差异及完整代码示例,助力AI运动场景深度拓展。
|
1月前
|
移动开发 Android开发
【03】建立隐私关于等相关页面和内容-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【03】建立隐私关于等相关页面和内容-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
115 0
|
1月前
|
数据采集 JavaScript 前端开发
开发比分App?你缺的不是程序员
开发体育比分App,关键不在代码,而在懂体育、懂数据、懂用户。明确定位、理清需求、选好数据源,再找专业的产品、数据与技术人才协同,才能少走弯路。程序员最后入场,效率最高。