四大央企是哪四大企业,上海网站优化排名,移动宽带续费网上营业厅,有限责任公司的设立条件有哪些【 声明#xff1a;版权所有#xff0c;欢迎转载#xff0c;请勿用于商业用途。 联系信箱#xff1a;feixiaoxing 163.com】 c# wpf最大的优势就是开发业务软件比较快、效率比较高。一般来说#xff0c;它的界面和逻辑部分可以同时开发。界面的部分用xaml编写即可#xf…【 声明版权所有欢迎转载请勿用于商业用途。 联系信箱feixiaoxing 163.com】 c# wpf最大的优势就是开发业务软件比较快、效率比较高。一般来说它的界面和逻辑部分可以同时开发。界面的部分用xaml编写即可代码的部分可以先用c#来完成。说到界面大部分的gui编辑工具都是基于gridstack的思想来进行设计的。这么说也许有点复杂简单一点说就有点类似于装修房子的概要设计和详细设计这两层意思。 概要设计主要就是先弄清楚房子里面哪里是厨房哪里是书房哪里是客厅哪里是过道这些都是先规划出来。详细设计就是某一个房间里面哪里放家具哪里放床哪里放电器这些。界面设计也是一样我们一般也是先简单归类下一个页面上大体有几个部分几行几列。等这些部分确定之后详细设计的时候我们再看应该选择什么样的控件前后左右距离多少大小多少什么样的颜色是否居中等等。 描述了上面一段文字大家可能还是云里雾里感觉比较绕我们不妨以一个计算器为范例看下应该如何用c#实现计算器的效果。 1、找一个计算器的参考图 计算器大家都比较熟悉。一般就是分成两部分。上面是一个小屏幕下面是按钮。初略来看的话其实就是这样。 2、手动或者用mspaint绘出一个效果图 如果图形比较复杂最好先手动绘制一下。当然也可以用windows自带的mspaint来进行绘制。这两种方式都是可以接受的。当然因为今天绘制的内容比较简单所以这里直接给出了xaml的最终效果图 仔细看一下效果图的话我们发现除了之前说的界面分成了上下两部分按钮这部分也做了一些细节的修改。比如全部数字部分都是黑底白字其他按钮都是灰色当然清零的按钮c变成了蓝色。当然如果做的更好看一点的话号这部分也可以做成绿色或者蓝色。 3、xaml设计 xaml的设计有点类似于网页设计。既然前面已经做出了最终的效果那么xaml的工作就是要通过脚本编写把这部分内容实现出来。本身gui分成了粗设计和精设计。在xaml这部分粗设计一般就是grid里面的行设计、列设计。而精设计这部分一般就是将众多控件当成一个stack横向排列或者纵向排列。至于这个stack占用多少行多少列这个就看外面的行和列范围。
Window x:ClassWpfApp.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfAppmc:IgnorabledTitleCalculator Height450 Width500GridGrid.RowDefinitionsRowDefinition Height80/RowDefinition//Grid.RowDefinitionsStackPanel Grid.Row0 Margin0,20,0,0TextBox Text0 FontSize40 BackgroundWhite ForegroundBlack Margin30,0,30,20 BorderThickness5 Width390 Height60 HorizontalAlignmentCenter HorizontalContentAlignmentRight//StackPanelStackPanel Grid.Row1 Margin0,20,0,20 OrientationVerticalStackPanel Margin30,0,30,0 OrientationHorizontal Width390 Height50 HorizontalAlignmentCenter Button BackgroundBlue ForegroundWhite ContentC Margin0,0,0,0 Width80/Button BackgroundGray ForegroundWhite Content Margin23,0,0,0 Width80/Button BackgroundGray ForegroundWhite Content% Margin23,0,0,0 Width80/Button BackgroundGray ForegroundWhite Content/ Margin23,0,0,0 Width80//StackPanelStackPanel Margin30,10,30,0 OrientationHorizontal Width390 Height50 HorizontalAlignmentCenter Button BackgroundBlack ForegroundWhite Content7 Margin0,0,0,0 Width80/Button BackgroundBlack ForegroundWhite Content8 Margin23,0,0,0 Width80/Button BackgroundBlack ForegroundWhite Content9 Margin23,0,0,0 Width80/Button BackgroundGray ForegroundWhite Content* Margin23,0,0,0 Width80//StackPanelStackPanel Margin30,10,30,0 OrientationHorizontal Width390 Height50 HorizontalAlignmentCenter Button BackgroundBlack ForegroundWhite Content4 Margin0,0,0,0 Width80/Button BackgroundBlack ForegroundWhite Content5 Margin23,0,0,0 Width80/Button BackgroundBlack ForegroundWhite Content6 Margin23,0,0,0 Width80/Button BackgroundGray ForegroundWhite Content- Margin23,0,0,0 Width80//StackPanelStackPanel Margin30,10,30,0 OrientationHorizontal Width390 Height50 HorizontalAlignmentCenter Button BackgroundBlack ForegroundWhite Content1 Margin0,0,0,0 Width80/Button BackgroundBlack ForegroundWhite Content2 Margin23,0,0,0 Width80/Button BackgroundBlack ForegroundWhite Content3 Margin23,0,0,0 Width80/Button BackgroundGray ForegroundWhite Content Margin23,0,0,0 Width80//StackPanelStackPanel Margin30,10,30,0 OrientationHorizontal Width390 Height50 HorizontalAlignmentCenter Button BackgroundBlack ForegroundWhite Content0 Margin0,0,0,0 Width80/Button BackgroundBlack ForegroundWhite Content00 Margin23,0,0,0 Width80/Button BackgroundBlack ForegroundWhite Content. Margin23,0,0,0 Width80/Button BackgroundGray ForegroundWhite Content Margin23,0,0,0 Width80//StackPanel/StackPanel/Grid
/Window整个代码部分还是比较容易理解的。首先整个界面的主轴是grid分成了上下两个部分。每一个行都有一个RowDefinition。接着在每一行里面都包含了一个StackPanel。 第一行的StackPanel比较简单它本身只包含了一个TextBox控件。 第二行的Stack则比较复杂一点因为在StackPanel里面又套了一层StackPanel。相当于20个按钮中每四个按钮构成一个StackPanel这样可以生成五个StackPanel。结果生成的五个StackPanel外面又包了一层StackPanel过程就是这样。 当然我们也看到每一个按钮也设定了一些基本属性比如Background和Foregound、Content这些信息当然没有里面提到Click部分主要因为今天主要讲的是设计代码实现的部分可以后期有时间继续补上。 4、gui布局的精粹 因为之前学过wxpython、qt今天又学习了c# wpf的xaml布局我们发现不管什么样的界面gridstack就是最最重要的布局思想。前者属于粗设计后者属于精设计。掌握了这一点不管什么样的界面设计应该都难不倒我们。 当然界面设计本身就是很繁琐的工作这件来来回回的修改一般都是少不了的。