WPF筆記(三)

quguiliang 14年前發布 | 3K 次閱讀 Evince

<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 2.7pt; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-outline-level: 3" class=MsoNormal align=left>WPF 控件一覽</P>

<P style="TEXT-ALIGN: left; MARGIN: 6.8pt 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>此處列出了內置的<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> WPF </SPAN>控件。<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>按鈕<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Button </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> RepeatButton</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>對話框<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>OpenFileDialog</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>PrintDialog </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> SaveFileDialog</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>數字墨跡<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>InkCanvas </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> InkPresenter</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>文檔<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>DocumentViewer</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>FlowDocumentPageViewer</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>FlowDocumentReader</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>FlowDocumentScrollViewer </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> StickyNoteControl</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>輸入<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>TextBox</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>RichTextBox </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> PasswordBox</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>布局<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Border</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>BulletDecorator</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Canvas</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>DockPanel</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Expander</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Grid</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>GridView</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>GridSplitter</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>GroupBox</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Panel</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>ResizeGrip</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Separator</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>ScrollBar</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>ScrollViewer</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>StackPanel</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Thumb</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Viewbox</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>VirtualizingStackPanel</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Window </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> WrapPanel</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>媒體<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Image</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>MediaElement </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> SoundPlayerAction</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>菜單<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>ContextMenu</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Menu </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> ToolBar</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>導航<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Frame</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Hyperlink</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Page</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>NavigationWindow </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> TabControl</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>選擇<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>CheckBox</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>ComboBox</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>ListBox</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>TreeView</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>RadioButton </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> Slider</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Symbol; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: Symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: Symbol" lang=EN-US>·                   </SPAN></SPAN>用戶信息<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>AccessText</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Label</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Popup</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>ProgressBar</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>StatusBar</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>TextBlock </SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> ToolTip</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-INDENT: 21.75pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>o:p /o:p</SPAN></P>

<P style="TEXT-INDENT: 21.75pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>o:p /o:p</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal>布局</P>

<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left><A name=Layout>創建</A> UI </SPAN>時,您通過按位置和大小排列控件來形成一種布局。任何布局的主要要求都是適應窗口大小和顯示設置的變化。</SPAN>WPF </SPAN>為您提供了一個一流的可擴展布局系統,而不是強制您編寫代碼以使布局適應這些情況。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; MARGIN: 6.8pt 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>布局系統的基礎是相對定位,它提高了適應窗口和顯示條件變化的能力。此外,布局系統還管理控件之間的協商以確定布局。協商過程分為兩步:第一步,控件向父控件通知它所需的位置和大小;第二步,父控件通知該控件它可以具有多大空間。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; MARGIN: 6.8pt 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>布局系統通過基本</SPAN> WPF </SPAN>類公開給子控件。對于通用的布局,如網格、堆疊和停靠,</SPAN>WPF </SPAN>包括了幾個布局控件:</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt" class=MsoNormal align=left>·                   </SPAN></SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Canvas</SPAN></SPAN>:子控件提供其自己的布局。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt" class=MsoNormal align=left>·                   </SPAN></SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>DockPanel</SPAN></SPAN>:子控件與面板的邊緣對齊。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt" class=MsoNormal align=left>·                   </SPAN></SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Grid</SPAN></SPAN>:子控件按行和列放置。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt" class=MsoNormal align=left>·                   </SPAN></SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>StackPanel</SPAN></SPAN>:子控件垂直或水平堆疊。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt" class=MsoNormal align=left>·                   </SPAN></SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>VirtualizingStackPanel</SPAN></SPAN>:子控件被虛擬化,并沿水平或垂直方向排成一行。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 21.75pt; mso-pagination: widow-orphan; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt" class=MsoNormal align=left>·                   </SPAN></SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>WrapPanel</SPAN></SPAN>:子控件按從左到右的順序放置,如果當前行中的控件數多于該空間所允許的控件數,則換至下一行。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; MARGIN: 6.8pt 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>下面的示例使用</SPAN> DockPanel </SPAN>排列幾個</SPAN> TextBox </SPAN>控件。</SPAN></SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US><Window</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    xmlns="

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    xmlns:x="

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    x:Class="SDKSample.LayoutWindow"</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    Title="Layout with the DockPanel" Height="143" Width="319"></SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>o:p /o:p</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>  <!--DockPanel to layout four text boxes--> </SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>  <DockPanel></SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    <TextBox DockPanel.Dock="Top">Dock = "Top"</TextBox></SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    <TextBox DockPanel.Dock="Bottom">Dock = "Bottom"</TextBox></SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    <TextBox DockPanel.Dock="Left">Dock = "Left"</TextBox></SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    <TextBox Background="White">This TextBox "fills" the remaining space.</TextBox></SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>  </DockPanel></SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>o:p /o:p</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US></Window></SPAN></P>

<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>DockPanel </SPAN>允許子<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> TextBox </SPAN>控件通知它如何排列這些子控件。為此,<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>DockPanel </SPAN>實現一個<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> Dock </SPAN>屬性,該屬性公開給子控件,以便每個子控件指定一個停靠樣式。<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>下圖演示了上一示例中<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> XAML </SPAN>標記的結果。<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US><?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter">/v:strokev:formulas<v:f eqn="if lineDrawn pixelLineWidth 0">/v:f<v:f eqn="sum @0 1 0">/v:f<v:f eqn="sum 0 0 @1">/v:f<v:f eqn="prod @2 1 2">/v:f<v:f eqn="prod @3 21600 pixelWidth">/v:f<v:f eqn="prod @3 21600 pixelHeight">/v:f<v:f eqn="sum @0 0 1">/v:f<v:f eqn="prod @6 1 2">/v:f<v:f eqn="prod @7 21600 pixelWidth">/v:f<v:f eqn="sum @8 21600 0">/v:f<v:f eqn="prod @7 21600 pixelHeight">/v:f<v:f eqn="sum @10 21600 0">/v:f/v:formulas<v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f">/v:path<o:lock aspectratio="t" v:ext="edit">/o:lock/v:shapetype<v:shape style="WIDTH: 239.25pt; HEIGHT: 117pt" id=_x0000_i1025 alt="DockPanel 頁" type="#_x0000_t75"><v:imagedata o:href="ms-help://MS.MSDNQTR.v90.chs/wpf_conceptual/art/WPFIntroFigure11.png" src="file:///C:\DOCUME~1\user\LOCALS~1\Temp\msohtml1\05\clip_image001.png">/v:imagedata/v:shapeo:p/o:p</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p /o:p</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal>數據綁定<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt" lang=EN-US>o:p/o:p</SPAN></P>

<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left><A name=Data_Binding>創建大多數應用程序的目的是為用戶提供查看和編輯數據的方式。對于</A> WPF </SPAN>應用程序,存儲和訪問數據的工作已經由</SPAN> Microsoft SQL Server </SPAN></SPAN> ADO.NET </SPAN>之類的技術提供。訪問數據并將數據加載到應用程序的托管對象中后,</SPAN>WPF </SPAN>應用程序的復雜工作才開始。實質上它涉及到兩個步驟:</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 29.2pt; mso-pagination: widow-orphan; mso-list: l2 level1 lfo3; tab-stops: list 36.0pt" class=MsoNormal align=left>1.           </SPAN></SPAN>將數據從托管對象復制到控件中,在控件上可以顯示和編輯數據。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; TEXT-INDENT: -18pt; MARGIN: 1.35pt 0cm 1.35pt 29.2pt; mso-pagination: widow-orphan; mso-list: l2 level1 lfo3; tab-stops: list 36.0pt" class=MsoNormal align=left>2.           </SPAN></SPAN>確保將使用控件對數據進行的更改復制回托管對象。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; MARGIN: 6.8pt 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>為了簡化應用程序開發,</SPAN>WPF </SPAN>提供了一個數據綁定引擎以自動執行這些步驟。數據綁定引擎的核心單元是</SPAN> Binding </SPAN>類,它的任務是將控件(綁定目標)綁定到數據對象(綁定源)。下圖說明了這種關系。</SPAN></SPAN></P>

<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left></SPAN></P>

<P style="TEXT-ALIGN: left; MARGIN: 6.8pt 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>下面的示例演示如何將</SPAN> TextBox </SPAN>綁定到自定義</SPAN> </SPAN>Person</SPAN> </SPAN>對象的實例。下面的代碼演示了</SPAN> </SPAN>Person</SPAN> </SPAN>的實現。</SPAN></SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>namespace SDKSample</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>{</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    class Person</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    {</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>        string name = "No Name";</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>o:p /o:p</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>        public string Name</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>        {</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>            get { return name; }</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>            set { name = value; }</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>        }</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>    }</SPAN></P>

<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>}</SPAN></P>

 本文由用戶 quguiliang 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!