当前位置:首页 > 谈天说地

WPF常用控件用法及介绍

34资源网2022-01-25687

1.groupbox

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

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

2.tabcontrol

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

所示的代码示意图:

<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同样可以接收任何类型的对象。这意味着可以创建一个组合框或选项卡。在他们的页标题中包含任意图形和任意元素。如下所示:

<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中很普遍, 用于左侧菜单。

代码如下所示:

<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能够包含一段嵌套的内容。

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

<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 属性, 修改其滚动的颜色。如下所示

<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, 前者是以一个日历的形式, 后者则像是一个文本框的形式。

<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常用控件用法及介绍的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持萬仟网。

版权声明:34楼发布

本文链接:https://www.34l.com/post/6318.html

分享给朋友:

相关文章

分享10句用哀鸿遍野造句大全

分享10句用哀鸿遍野造句大全

1、在旧社会,每逢水旱战乱,人民就被迫四处逃亡,哀鸿遍野,一片凄凉。…

100元内最好的音箱选择哪种好?看看这款适合你不?

100元内最好的音箱选择哪种好?看看这款适合你不?

目前市面上的音箱种类繁多,有的音质非常好,有的音质比较差,有些朋友酷爱音乐,可是又不想花太多钱在这些音箱上面,一般都会选择一些100元以内的音箱。那么100元内最好的音箱选择哪种好?下面,小编给大家推荐一款迷你型的小音箱,大家一起来看看吧。…

抖音如果让我遇见你而你正当年轻是什么歌曲?

抖音如果让我遇见你而你正当年轻是什么歌曲?

《抖音》短视频平台上有不少老歌经过翻唱火了,可能刚好歌词传递的情感引起了网友们的共鸣,而最近比较火的一首歌歌词大概是如果让我遇见你而你正当年轻,好多网友不知道首是什么歌曲?小编刚开始也不知道,后来经过搜索得知这是一首老歌《怨苍天变了心》,是…

曹德旺的经典语录分享

曹德旺的经典语录分享

曹德旺,福耀玻璃集团创始人、董事长。中国反倾销胜诉第一人、中国首善、安永企业家奖首位华人获得者 。福耀玻璃目前是中国第一、世界第二大汽车玻璃供应商。他是不行贿的企业家,自称“没送过一盒月饼”,以人格做事;他是行善的佛教徒,从1983年第一次…

区块链开发技术有前景吗(区块链技术开发费用)

由于人们对大数据、区块链、人工智能行业的认识越来越深入,企业可以通过大数据、区块链、人工智能等思维和技术寻求变革。传统行业依靠原有产业优势“后来居上”,低调布局区块链技术,传统产业企业和科技企业同时进入产业区块链赛道。在区块链发展报告中,我…

ab压力测试命令(在线ddos免费测压平台)

ab压力测试命令(在线ddos免费测压平台)

ab 是apache对 http服务器进行压力测试的工具,它可以测试出服务器每秒可以处理多少请求。本文记录mac版本安装 ab 的步骤以及遇到的坑。 下载 进入 apache ab官网 下载页面。 安装 brew 安装 因为笔者的操作系统…