wpf XMLDataProvider

csharp 复制代码
 <Window.Resources>
     <!--Data Template-->
     <DataTemplate DataType="Ut">
         <Grid>
             <StackPanel Orientation="Horizontal">
                 <Grid>
                     <Rectangle Stroke="Yellow" Fill="Orange" Width="{Binding XPath=@Price}"/>
                     <TextBlock Text="{Binding XPath=@Year}"/>
                 </Grid>
                 <TextBlock Text="{Binding XPath=@Price}" Margin="5.0"/>
             </StackPanel>
         </Grid>
     </DataTemplate>
     <XmlDataProvider x:Key="ds" XPath="Units/Unit/Ut">
         <x:XData>
             <Units xmlns="">
                 <Unit Year="2001" Price="100">
                     <Ut Year="3001" Price="300"></Ut>
                 </Unit>
                 <Unit Year="2001" Price="120"/>
                 <Unit Year="2001" Price="140"/>
                 <Unit Year="2001" Price="160"/>
                 <Unit Year="2001" Price="180"/>
                 <Unit Year="2001" Price="200"/>
             </Units>
         </x:XData>
     </XmlDataProvider>
 </Window.Resources>
 <Grid >

     <StackPanel>
         <ListBox ItemsSource="{Binding Source={StaticResource ds}}"/>
         <ComboBox ItemsSource="{Binding Source={StaticResource ds}}" Margin="5"/>
     </StackPanel>
 </Grid>
csharp 复制代码
 <Window.Resources>
         <!--<XmlDataProvider x:Key="ItemsDataProvider" XPath="/Items/Item">
             <x:XData>
                 <Items xmlns="">
                     <Item>Item1</Item>
                     <Item>Item2</Item>
                     <Item>Item3</Item>
                 </Items>
             </x:XData>
         </XmlDataProvider>-->
     <XmlDataProvider x:Key="ItemsDataProvider" XPath="/Items/Item" Source="./DataSources/XMLFile1.xml">
         
     </XmlDataProvider>
     </Window.Resources>
     <Grid>
         <ComboBox  ItemsSource="{Binding Source={StaticResource ItemsDataProvider}}" />
     </Grid>
相关推荐
烟话64 天前
MVVM核心机制:属性通知与命令绑定解析
wpf
不知名君4 天前
WPF 的原生窗体标题栏主题自适应系统深浅主题
wpf
碎碎念的安静4 天前
WPF 与 Qt 进程间通信(IPC)
开发语言·qt·wpf
军训猫猫头5 天前
7.带输入参数的线程启动 C# + WPF 完整示例
开发语言·前端·c#·.net·wpf
周杰伦fans5 天前
WPF Prism 框架完全入门指南:从环境搭建到弹窗导航实战
wpf
雨浓YN5 天前
WPF MVVM 模式(无调库)项目创建笔记
笔记·wpf
周杰伦fans6 天前
.NET AOT技术深度解析:为什么WPF不支持而Avalonia/UWP支持?
.net·wpf
雨浓YN6 天前
WPF MVVM 模式(调Prism库)项目创建笔记 —— 包含C++/CLI OpenCV互操作
c++·笔记·wpf
七夜zippoe6 天前
DolphinDB数据模型:表、分区与分布式表
分布式·wpf·数据模型··dolphindb
一念春风7 天前
Qwen2.5 (AI模型 PC搭建)
人工智能·ai·c#·wpf·模型