WPF常用控件用法及介紹
1.GroupBox

注意: GroupBox仍然需要布局容器來放置元素。如: StackPanel面板
<GroupBox Header="select number?">
<StackPanel>
<RadioButton>one</RadioButton>
<RadioButton>two</RadioButton>
<RadioButton>three</RadioButton>
</StackPanel>
</GroupBox>2.TabControl
像這種標(biāo)簽頁控件, 在winform種非常常見, Tabpge子頁面, 而在WPF種, 對(duì)應(yīng)的則是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同樣可以接收任何類型的對(duì)象。這意味著可以創(chuàng)建一個(gè)組合框或選項(xiàng)卡。在他們的頁標(biāo)題中包含任意圖形和任意元素。如下所示:

<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菜單控件
具備標(biāo)題的內(nèi)容收縮控件, 在web中很普遍, 用于左側(cè)菜單。

代碼如下所示:
<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控件是一個(gè)非常靈活的控件, 它不僅包含子元素ListBoxItem對(duì)象。而且也可以駐留其他元素, 這也就是ListBoxItem類繼承于ContentControl類,從而ListBoxItem能夠包含一段嵌套的內(nèi)容。
例如, 創(chuàng)建一個(gè)包含普通按鈕的列表。如下所示:

<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進(jìn)度條
IsIndeterminate屬性設(shè)置為True, 控件則會(huì)周期性的顯示一個(gè)綠色(默認(rèn))從左到右的脈沖。
<Grid>
<ProgressBar IsIndeterminate="True" Height="30"></ProgressBar>
</Grid>當(dāng)然, 我們也可以通過修改Foreground 屬性, 修改其滾動(dòng)的顏色。如下所示

<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中有兩個(gè)日期控件,Calendar和DatePicker, 前者是以一個(gè)日歷的形式, 后者則像是一個(gè)文本框的形式。

<StackPanel>
<DatePicker></DatePicker>
<Calendar></Calendar>
</StackPanel>同時(shí), 控件還具備眾多屬性。
DisplayDateStart 和 DisplayDateEnd | 設(shè)置在日歷視圖中顯示的日期范闈,從第一個(gè)妯早的日期(DisplayDateStart)到最后最近 的日期(DisplayDateEnd),用戶不能導(dǎo)航到?jīng)]打包含能夠顯示的日期的月份。為了顯示所 有日期,可以將DisplayDateStart屬性設(shè)置為DateTime.MinValue,并將DisplayDateEnd W性設(shè)置為DateTime.MaxValue |
| BlackoutDates | 保存在日歷中將被禁用或不能選擇的日期集合?如果這呰日期不在可以顯示的曰期范ra 內(nèi),或芥如果己經(jīng)選擇了這些曰期中的蓯個(gè)日期,將接收到一個(gè)異常, 為了阻止選擇任 何過去的日期,可以調(diào)用BlackoutDates.AddDatcsInPast()方法 |
| SelectedDate | 作為一個(gè)DateTime對(duì)象提供選擇的日期(或名?沒冇日期被選中時(shí)使用null值)??梢酝ㄟ^ 代碼、通過單擊日歷中的日期、或通過用戶鍵入一個(gè)日期字符審(在DatePicker控件中> 設(shè)置該屬性.在日歷視圖中,選抒的日期使用一個(gè)具有陰影的方框標(biāo)識(shí),只有當(dāng)曰期控 件具有焦點(diǎn)時(shí)才會(huì)顯示該方框 |
| SelectedDates | 作為 DateTime 對(duì)象的集合提供選擇的日期。 Calcndar 控件支持該屬性,并目.只有當(dāng)修改了 SelectionMode 屬性,以允許選擇多個(gè)日期時(shí),該屬性才有用 |
| DispalyDate | (使用Datetime 對(duì)象確定在日歷視圖中最初顯示的日期.如果該屬性為空,顯示selectedDate屬性的值。如果 DisPlayDate 和 select 曰 LDate 屬性均為空,使用當(dāng)前日期.顯示的日期決定了日歷視圖中最初的月份頁面。當(dāng)日期控件具有焦點(diǎn)時(shí),在該月份中恰當(dāng)?shù)哪程熘車@示一個(gè)方形邊框(該邊框和用于當(dāng)前選擇日期的陰影方框是有區(qū)別的) |
| FristDayOfweek | 確定在日歷中每行的開始位置(最左邊)顯示一星期中的哪一天 |
| IsToDayHighighted | 確定日歷視圖是否通過突出顯示指出當(dāng)前日期 |
到此這篇關(guān)于WPF常用控件用法及介紹的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
c# 讀取文件內(nèi)容存放到int數(shù)組 array.txt
c# 讀取文本的內(nèi)容,并且將內(nèi)容保存到int數(shù)組中,大家可以學(xué)習(xí)到c#一些數(shù)組跟讀取內(nèi)容的函數(shù)。2009-04-04
ASP.NET Core 集成 React SPA應(yīng)用的步驟
這篇文章主要介紹了ASP.NET Core 集成 React SPA應(yīng)用的步驟,幫助大家更好的理解和學(xué)習(xí)使用.net技術(shù),感興趣的朋友可以了解下2021-04-04
ASP.NET過濾HTML標(biāo)簽只保留換行與空格的方法
這篇文章主要介紹了ASP.NET過濾HTML標(biāo)簽只保留換行與空格的方法,包含網(wǎng)上常見的方法以及對(duì)此方法的改進(jìn),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12
運(yùn)用.NetCore實(shí)例講解RabbitMQ死信隊(duì)列,延時(shí)隊(duì)列
這篇文章主要運(yùn)用.NetCore實(shí)例講解RabbitMQ死信隊(duì)列,延時(shí)隊(duì)列,,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2021-09-09

