WPF数据绑定案例

WPF数据绑定案例,效果和代码如下:
在这里插入图片描述

<Window x:Class="DataBindingDemo.MainWindow"
        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:DataBindingDemo"
        mc:Ignorable="d"
        Title="List of Products" SizeToContent="WidthAndHeight">
    <Window.Resources>
            <DataTemplate x:Key="GroupingHeaderTemplate">
                <TextBlock Text="{Binding Path=Name}" Style="{StaticResource GroupHeaderStyle}"/>
            </DataTemplate>

            <CollectionViewSource
                Source="{Binding Source={x:Static Application.Current}, Path=AuctionItems}"
                x:Key="ListingDataView" />
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="300" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.ColumnSpan="3"
                   Style="{StaticResource TitleStyle}" Margin="8,20,8,8"
                   AutomationProperties.HeadingLevel = "Level1" 
                   AutomationProperties.Name="{Binding RelativeSource={RelativeSource Self}, Path=Text}">
            List of items for sale:
        </TextBlock>
        <CheckBox Name="Grouping" Grid.Row="1" Grid.Column="0"
                  Checked="AddGrouping" Unchecked="RemoveGrouping"
                  Margin="8" Style="{StaticResource CheckBoxStyle}">
            Group by category
        </CheckBox>
        <CheckBox Name="Filtering" Grid.Row="1" Grid.Column="1"
                  Checked="AddFiltering" Unchecked="RemoveFiltering"
                  Margin="8" Style="{StaticResource CheckBoxStyle}">
            Show only bargains
        </CheckBox>
        <CheckBox Name="Sorting" Grid.Row="1" Grid.Column="2"
                  Checked="AddSorting" Unchecked="RemoveSorting"
                  Margin="8" Style="{StaticResource CheckBoxStyle}">
            Sort by category and date
        </CheckBox>


        <ListBox Name="Master" AutomationProperties.Name="Items For Sale" Grid.Row="2" Grid.ColumnSpan="3" Margin="8"
                 ItemsSource="{Binding Source={StaticResource ListingDataView}}"
                 ItemContainerStyle="{StaticResource AuctionItemContainerStyle}"
                 AutomationProperties.LiveSetting="Assertive">
            <ListBox.GroupStyle>
                <GroupStyle
                    HeaderTemplate="{StaticResource GroupingHeaderTemplate}" />
            </ListBox.GroupStyle>
        </ListBox>


        <ContentControl Name="Detail" Grid.Row="3" Grid.ColumnSpan="3"
                        Content="{Binding Source={StaticResource ListingDataView}}"
                        ContentTemplate="{StaticResource DetailsProductListingTemplate}"
                        Margin="9,0,0,0" IsTabStop="False"/>
        <Button Name="OpenAddProduct" Grid.Row="4" Grid.Column="1" Content="Add Product" HorizontalAlignment="Center"
                Margin="8"
                Click="OpenAddProductWindow" />
        
    </Grid>
</Window>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向着光-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值