欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

WPF常用控件用法及介绍

程序员文章站 2022-03-02 14:43:31
1.groupbox注意: groupbox仍然需要布局容器来放置元素。如: stackpanel面板 &l...

1.groupbox

WPF常用控件用法及介绍

注意: groupbox仍然需要布局容器来放置元素。如: stackpanel面板

<groupbox header="select number?">
       <stackpanel>
           <radiobutton>one</radiobutton>
           <radiobutton>two</radiobutton>
           <radiobutton>three</radiobutton>
       </stackpanel>
   </groupbox>

2.tabcontrol

像这种标签页控件, 在winform种非常常见, tabpge子页面, 而在wpf种, 对应的则是tabitem类。

WPF常用控件用法及介绍

所示的代码示意图:

<tabcontrol>
        <tabitem header="首页">
            <stackpanel>
                <button>button1</button>
                <button>button2</button>
                <button>button3</button>
            </stackpanel>
        </tabitem>
 
        <tabitem header="第二页">
            <stackpanel>
                <button>button4</button>
                <button>button5</button>
                <button>button6</button>
            </stackpanel>
        </tabitem>
         
    </tabcontrol>

与content属性相同, tabitem的header同样可以接收任何类型的对象。这意味着可以创建一个组合框或选项卡。在他们的页标题中包含任意图形和任意元素。如下所示:

WPF常用控件用法及介绍

<tabcontrol>
        <tabitem >
            <tabitem.header>
                <stackpanel orientation="horizontal">
                    <button background="transparent" borderbrush="transparent">♥</button>
                    <textbox borderbrush="transparent">首页</textbox>
                </stackpanel>
            </tabitem.header>
 
            <stackpanel>
                <button>button1</button>
                <button>button2</button>
                <button>button3</button>
            </stackpanel>
 
        </tabitem>
    </tabcontrol>

3.expander菜单控件

具备标题的内容收缩控件, 在web中很普遍, 用于左侧菜单。

WPF常用控件用法及介绍

代码如下所示:

<stackpanel>
    <expander header="one" margin="5" padding="5">
        <textblock textwrapping="wrap">ofo has been favored by the public, even the foreign people speak highly of it. these yellow
            bikes can be found everywhere, so the people who are in a hurry can
            use it and then reached the destination in time.</textblock>
    </expander>
 
    <expander header="two" margin="5" padding="5">
        <textblock textwrapping="wrap">especially for the visitors, they can ride these bikes and then have a look at the scenery around.</textblock>
    </expander>
 
    <expander header="three" margin="5" padding="5">
        <textblock textwrapping="wrap">it can saves them a lot of money and the most important thing is the convenience it brings.</textblock>
    </expander>
 
</stackpanel>

4.listbox控件

listbox控件是一个非常灵活的控件, 它不仅包含子元素listboxitem对象。而且也可以驻留其他元素, 这也就是listboxitem类继承于contentcontrol类,从而listboxitem能够包含一段嵌套的内容。

例如, 创建一个包含普通按钮的列表。如下所示:

WPF常用控件用法及介绍

<stackpanel>
       <listbox>
           <listboxitem>
               <button>♥ button1</button>
           </listboxitem>
       </listbox>
 
       <listbox>
           <listboxitem>
               <button>♥ button2</button>
           </listboxitem>
       </listbox>
 
       <listbox>
           <listboxitem>
               <button>♥ button3</button>
           </listboxitem>
       </listbox>
   </stackpanel>

5. progressbar进度条

isindeterminate属性设置为true, 控件则会周期性的显示一个绿色(默认)从左到右的脉冲。

<grid>
    <progressbar isindeterminate="true" height="30"></progressbar>
</grid>

当然, 我们也可以通过修改foreground 属性, 修改其滚动的颜色。如下所示

WPF常用控件用法及介绍

<stackpanel>
    <progressbar margin="2" isindeterminate="true" height="30" foreground="green" ></progressbar>
    <progressbar margin="2" isindeterminate="true" height="30" foreground="red" ></progressbar>
    <progressbar margin="2" isindeterminate="true" height="30" foreground="chocolate" ></progressbar>
    <progressbar margin="2" isindeterminate="true" height="30" foreground="darksalmon" ></progressbar>
    <progressbar margin="2" isindeterminate="true" height="30" foreground="pink" ></progressbar>
    <progressbar margin="2" isindeterminate="true" height="30" foreground="dodgerblue" ></progressbar>
</stackpanel>

6.日期控件

wpf中有两个日期控件,calendar和datepicker, 前者是以一个日历的形式, 后者则像是一个文本框的形式。

WPF常用控件用法及介绍

<stackpanel>
      <datepicker></datepicker>
      <calendar></calendar>
  </stackpanel>

同时, 控件还具备众多属性。

displaydatestart

displaydateend

设置在日历视图中显示的日期范闱,从第一个妯早的日期(displaydatestart)到最后最近

的日期(displaydateend),用户不能导航到没打包含能够显示的日期的月份。为了显示所

有日期,可以将displaydatestart属性设置为datetime.minvalue,并将displaydateend

w性设置为datetime.maxvalue

 blackoutdates

保存在日历中将被禁用或不能选择的日期集合?如果这呰日期不在可以显示的曰期范ra

内,或芥如果己经选择了这些曰期中的苁个日期,将接收到一个异常, 为了阻止选择任

何过去的日期,可以调用blackoutdates.adddatcsinpast()方法

 selecteddate

作为一个datetime对象提供选择的日期(或名?没冇日期被选中时使用null值)。可以通过

代码、通过单击日历中的日期、或通过用户键入一个日期字符审(在datepicker控件中>

设置该属性.在日历视图中,选抒的日期使用一个具有阴影的方框标识,只有当曰期控

件具有焦点时才会显示该方框

 selecteddates  作为 datetime 对象的集合提供选择的日期。 calcndar 控件支持该属性,并目.只有当修改了 selectionmode 属性,以允许选择多个日期时,该属性才有用
 dispalydate  (使用datetime 对象确定在日历视图中最初显示的日期.如果该属性为空,显示selecteddate属性的值。如果 displaydate 和 select 曰 ldate 属性均为空,使用当前日期.显示的日期决定了日历视图中最初的月份页面。当日期控件具有焦点时,在该月份中恰当的某天周围显示一个方形边框(该边框和用于当前选择日期的阴影方框是有区别的)
 fristdayofweek  确定在日历中每行的开始位置(最左边)显示一星期中的哪一天
 istodayhighighted  确定日历视图是否通过突出显示指出当前日期

到此这篇关于wpf常用控件用法及介绍的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持。