Windows Presentation Foundation(WPF)涓殑鏁版嵁缁戝畾锛堜娇鐢╔mlDataProvider浣滄帶浠剁粦瀹氾級
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windows Presentation Foundation(WPF)涓殑鏁版嵁缁戝畾锛堜娇鐢╔mlDataProvider浣滄帶浠剁粦瀹氾級相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/hive' title='hive'>hive
arch width 涓ょ 鍒嗕韩鍥剧墖 hotmail news div HSM 鍘熸枃:Windows Presentation Foundation(WPF)涓殑鏁版嵁缁戝畾锛堜娇鐢╔mlDataProvider浣滄帶浠剁粦瀹氾級
--------------------------------------------------------------------------------
寮曠敤鎴栬浆杞芥椂璇蜂繚鐣欎互涓嬩俊鎭細
澶у彲灞?/strong>?[MSN:a3news(AT)hotmail.com]
http://www.zpxp.com?http://www.brawdraw.com
钀濆崪榧犲湪绾垮浘褰㈠浘鍍忓鐞?br>--------------------------------------------------------------------------------
涓婄瘒锛?a href="http://blog.csdn.net/johnsuna/archive/2007/08/21/1752865.aspx" rel="nofollow">Windows Presentation Foundation(WPF)涓殑鏁版嵁缁戝畾锛堟帶浠朵笌鎺т欢鍊肩殑缁戝畾锛?/a>?涓€鏂囦腑璁蹭簡浣跨敤{Binding ElementName=xxx,Path=xxx}鐨勫舰寮忓疄鐜颁簡鎺т欢鍒版帶浠剁殑缁戝畾锛屾敞鎰忓畠浣跨敤浜?strong>ElementName灞炴€с€傛湰绡囧皢璇磋濡備綍浣跨敤XmlDataProvider浣滄帶浠剁粦瀹氾紝浣嗗畠浣跨敤Source 灞炴€с€?/p>
瀵逛簬澶у鏁板簲鐢ㄧ▼搴忥紝鎴戜滑甯屾湜缁戝畾鍒癤ML鎴?.NET 瀵硅薄銆傛瘮濡俋ML鏂囦欢鎴栬€呰嚜瀹氫箟鐨?Net瀵硅薄锛屾垨鑰呮槸鎴戜滑浠庢暟鎹簱涓彇鍑虹殑鐩稿簲璁板綍銆?/p>
XAML 鐢ㄥ叾 Provider 瀵硅薄鏀寔璇ユ搷浣溿€俋AML 涓唴缃湁涓ょ绫诲瀷鐨勬暟鎹彁渚涚▼搴忥細ObjectDataProvider 鍜?XMLDataProvider銆傚叾涓紝ObjectDataProvider 鐢ㄤ簬缁戝畾鍒?.NET 瀵硅薄浠ュ強浠?.NET 瀵硅薄缁戝畾锛沊MLDataProvider 鐢ㄤ簬缁戝畾鍒?XML 鐗囨鍜屾枃妗d互鍙婁粠 XML 鐗囨鍜屾枃妗h繘琛岀粦瀹氥€?/p>
2. XMAL鏂囦欢鍐呴儴鏁版嵁鐨勭洿鎺ョ粦瀹氾細
棣栧厛鎴戜滑鏉ョ湅鐪嬬洿鎺ュ湪XAML涓浣曚娇鐢╔MLDataProvider杩涜鍐呴儴鏁版嵁鐨勭洿鎺ョ粦瀹氥€?br><Window
?xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
?xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
?x:Class="WPFDataBinding.Window1"
?x:Name="Window"
?Title="Window1"
?>
<Canvas x:Name="LayoutRoot">
<StackPanel Width="214" Height="Auto">
?? <StackPanel.Resources>
???? <XmlDataProvider x:Key="FavoriteColors">
?????? <x:XData>
???????? <Colors xmlns="">
?????????? <Color>绾?lt;/Color>
?????????? <Color>姗?lt;/Color>
?????????? <Color>榛?lt;/Color>
?????????? <Color>缁?lt;/Color>?
?????????? <Color>钃?lt;/Color>
?????????? <Color>闈?lt;/Color>
?????????? <Color>绱?lt;/Color>
???????? </Colors>
?????? </x:XData>
??? </XmlDataProvider>
?? </StackPanel.Resources>
?? <TextBlock HorizontalAlignment="Center" FontWeight="Bold">
????? 鍠滄鐨勯鑹?
?? </TextBlock>
?? <ListBox Width="200" Height="120"
?????????????? ItemsSource="{Binding Source={StaticResource FavoriteColors},?XPath=/Colors/Color}">
?? </ListBox>
</StackPanel>
</Canvas>
</Window>
鍙互鐪嬪埌锛屽湪 StackPanel 鐨勮祫婧愶紙<StackPanel.Resources> 锛変腑锛屾湁涓€涓?XMLDataProvider 瀵硅薄銆倄:Key 琛ㄧず Binding 瀵硅薄涓敤鏉ュ紩鐢ㄥ畠鐨勫悕绉般€傝繖閲岋紝鎴戜滑鍒涘缓浜?XML 鍐呰仈鏁版嵁锛堟暟鎹娇鐢?font style="background-color:#ffcc99;"><x:XData>鏍囩鍖呭惈璧锋潵锛屽叧浜嶺Data鐨勭粏鑺傦紝寤鸿浣犳煡鏌SDN锛歮s-help://MS.LHSMSSDK.1033/MS.LHSNETFX30SDK.1033/wpf_conceptual/html/7ce209c2-621b-4977-b643-565f7e663534.htm锛屾湁鏇磋缁嗙殑璇存槑锛夛紝鐢ㄤ綔鏁版嵁缁戝畾鐨勬簮銆傚湪 ListBox 鐨?Binding 涓紝浣跨敤FavoriteColors鐨凷taticResource浣滀负Source銆傚鏋滄煇涓暟鎹簮浣嶄簬 XAML 鏂囨。涓紝鎴戜滑灏辫鎸囧畾璇ュ璞℃槸涓€涓潤鎬佹簮锛圫taticResource锛夛紝姝e杩欓噷鎵€鐪嬪埌鐨勪竴鏍枫€傛渶鍚庯紝鎴戜滑浣跨敤 XPath 璇彞鎸囧畾搴旇浣跨敤 XML 鏂囨。涓殑鍝釜闆嗗悎鏉ュ~鍏?ListBox銆?/p>
鏈€鍚庣殑缁撴灉锛?br>
以上是关于Windows Presentation Foundation(WPF)涓殑鏁版嵁缁戝畾锛堜娇鐢╔mlDataProvider浣滄帶浠剁粦瀹氾級的主要内容,如果未能解决你的问题,请参考以下文章
Windows Presentation Foundation(WPF)项目中不支持网格
Windows Presentation Foundation (WPF) 项目中不支持xxx的解决
Windows Presentation Foundation (WPF) 项目不支持应用程序
在 Windows Presentation Foundation 中使用 MVC 而不是 MVVM