C# WPF 通过 XAML 添加数据绑定性列表项到 ListView

算得上是一种奇技淫巧了吧。用 ListView(简直万能)模拟 Tab 时会用到。

首先自定义类型 TabItem

namespace MyType
{
    public struct TabItem
    {
        public ImageSource Icon { get; set; }
        public String Title { get; set; }
    }
}
        <ListView Background="#00FFFFFF" 
                  BorderThickness="0"
                  ScrollViewer.HorizontalScrollBarVisibility="Disabled"  
                  x:Name="ProgramListBox" HorizontalAlignment="Left"
                  Height="345" Margin="10,35,0,0" VerticalAlignment="Top" 
                  Width="187">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Height="32" Width="32" Source="{Binding Icon}"></Image>
                         <TextBlock Text="{Binding Title}" FontSize="18" Height="32"></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ListView.ItemsSource>
                <col:ArrayList>
                    <models:TabItem Title="Tab Item 1" />
                    <models:TabItem Title="Tab Item 2" />
                </col:ArrayList>
            </ListView.ItemsSource>
        </ListView>

发表留言

本站启用了垃圾评论检测插件,如果误删请联系我~