要准备

1.自定义类型  MyObj(需继承INotifyPropertyChanged)

2.自定义类型集合类  MyObjs(需继承ObservableCollection<MyObj>)

如下:

 自定义类型

<Window x:Class="WpfApplication1.MainWindow"
        xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys
="clr-namespace:System;assembly=mscorlib"
        xmlns:local
="clr-namespace:My"
        Title
="MainWindow" Height="506" Width="880" Loaded="Window_Loaded">
    
<Window.Resources>
        
<local:People  x:Key="MyDataSource"></local:People>
    
</Window.Resources>
<Grid>
 
<ListBox ItemsSource="{StaticResource MyDataSource}">
        
<!--<ListBox ItemsSource="{Binding Source={StaticResource MyDataSource}}">这样写也可以-->
 
</ListBox>
</Grid>
</Window>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2021-10-19
  • 2021-07-09
  • 2021-12-13
猜你喜欢
  • 2021-10-29
  • 2021-12-14
  • 2021-06-18
  • 2021-06-13
  • 2022-12-23
  • 2022-02-09
相关资源
相似解决方案