c# wpf XmlDataProvider 简单试验

1.概要

2.代码

<Window x:Class="WpfApp2.Window12"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp2"
        mc:Ignorable="d"
        Title="Window12" Height="450" Width="800">
    <Window.Resources>
        <!--Data Template-->
        <DataTemplate DataType="Unit">
            <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">
            <x:XData>
                <Units xmlns="">
                    <Unit Year="2001" Price="100"/>
                    <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>
    <StackPanel>
        <ListBox ItemsSource="{Binding Source={StaticResource ds}}"/>
        <ComboBox ItemsSource="{Binding Source={StaticResource ds}}" Margin="5"/>
    </StackPanel>
</Window>

3.试验结果

相关推荐

  1. 简单试验:用Excel进行爬虫

    2024-04-07 05:56:03       46 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-07 05:56:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-07 05:56:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-07 05:56:03       82 阅读
  4. Python语言-面向对象

    2024-04-07 05:56:03       91 阅读

热门阅读

  1. Android ContentProvider基础知识学习笔记

    2024-04-07 05:56:03       39 阅读
  2. vue 生命周期

    2024-04-07 05:56:03       38 阅读
  3. [蓝桥杯 2023 国 B] 双子数

    2024-04-07 05:56:03       39 阅读
  4. ARXML处理 - C#的解析代码(一)

    2024-04-07 05:56:03       32 阅读
  5. Python常用算法--排序算法【附源码】

    2024-04-07 05:56:03       42 阅读
  6. 沐瞳科技一面 客户端开发(45min)

    2024-04-07 05:56:03       43 阅读
  7. CSS编写登录框样式

    2024-04-07 05:56:03       45 阅读
  8. asio中socket的打开

    2024-04-07 05:56:03       66 阅读
  9. 计算机网络(目录)

    2024-04-07 05:56:03       39 阅读
  10. OJ题目分享2

    2024-04-07 05:56:03       82 阅读
  11. 彩虹易支付搭建教程

    2024-04-07 05:56:03       39 阅读
  12. .NET9 PreView2+.AOT ILC 的重大变化

    2024-04-07 05:56:03       173 阅读