【转】WPF 入门《常用控件》
1.GroupBox
注意: GroupBox仍然需要布局容器來放置元素。如: StackPanel面板
| 1 2 3 4 5 6 7 | <GroupBox Header="select number?"> ???????<StackPanel> ???????????<RadioButton>one</RadioButton> ???????????<RadioButton>two</RadioButton> ???????????<RadioButton>three</RadioButton> ???????</StackPanel> ???</GroupBox> |
?
2.TabControl
? 像這種標簽頁控件, 在winform種非常常見, Tabpage做子頁面, 而在WPF種, 對應的則是TabItem類。
?所示的代碼示意圖:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <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同樣可以接收任何類型的對象。這意味著可以創建一個組合框或選項卡。在他們的頁標題中包含任意圖形和任意元素。如下所示:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <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中很普遍, 用于左側菜單。
?
?代碼如下所示:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <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能夠包含一段嵌套的內容。
?
例如, 創建一個包含普通按鈕的列表。如下所示:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <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, 控件則會周期性的顯示一個綠色(默認)從左到右的脈沖。
?
| 1 2 3 | <Grid> ????<ProgressBar IsIndeterminate="True"?Height="30"></ProgressBar> </Grid> |
?
當然, 我們也可以通過修改Foreground 屬性, 修改其滾動的顏色。如下所示
| 1 2 3 4 5 6 7 8 | <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, 前者是以一個日歷的形式, 后者則像是一個文本框的形式。
| 1 2 3 4 | <StackPanel> ??????<DatePicker></DatePicker> ??????<Calendar></Calendar> ??</StackPanel> |
?同時, 控件還具備眾多屬性。
| DisplayDateStart和 DisplayDateEnd |
的日期(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 入门《常用控件》的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 16万起!股神巴菲特最后的慈善午餐仅1人
- 下一篇: 万亿“迪王”不是终点 比亚迪被看好市值可