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>鎶€鏈垎浜浘鐗? alt=








































以上是关于Windows Presentation Foundation(WPF)涓殑鏁版嵁缁戝畾锛堜娇鐢╔mlDataProvider浣滄帶浠剁粦瀹氾級的主要内容,如果未能解决你的问题,请参考以下文章

Windows Presentation Foundation(WPF)项目中不支持网格

Windows Presentation Foundation (WPF) 项目中不支持xxx的解决

Windows Presentation Foundation (WPF) 项目不支持应用程序

在 Windows Presentation Foundation 中使用 MVC 而不是 MVVM

我的 C# .NET 团队是不是应该迁移到 Windows Presentation Foundation? [关闭]

vuejs Newline required at end of file but not foun