国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
WPF中的TreeView控件_銀光中國 Silverlight 資源 社區(qū) 論壇
時間:2010-12-24 01:18來源:百度空間 作者:2sws 點(diǎn)擊:170次
TreeView繼承于HeaderedItemsControl類,而HeaderedItemsControl類又繼承于ItemsControl類,所也TreeView同時會擁有ItemsSource屬性設(shè)置數(shù)據(jù)源;DisplayMemberPath設(shè)置數(shù)據(jù)項(xiàng)顯示內(nèi)容;ItemContainerStyle屬性設(shè)置TreeViewItem數(shù)據(jù)項(xiàng)的樣式;ItemContainerStyleSelector屬性設(shè)置TreeViewItem數(shù)據(jù)項(xiàng)樣式選擇器;ItemsPanel屬性
  

  TreeView繼承于HeaderedItemsControl類,而HeaderedItemsControl類又繼承于ItemsControl類,所也TreeView同時會擁有ItemsSource屬性設(shè)置數(shù)據(jù)源;DisplayMemberPath設(shè)置數(shù)據(jù)項(xiàng)顯示內(nèi)容;ItemContainerStyle屬性設(shè)置TreeViewItem數(shù)據(jù)項(xiàng)的樣式;ItemContainerStyleSelector屬性設(shè)置TreeViewItem數(shù)據(jù)項(xiàng)樣式選擇器;ItemsPanel屬性設(shè)置數(shù)據(jù)項(xiàng)的容器;ItemsPanel屬性設(shè)置數(shù)據(jù)項(xiàng)容器的選擇器;GroupStyle屬性顯示數(shù)據(jù)分組;GroupStyleSelector屬性設(shè)置數(shù)據(jù)分組選擇器。

  與ListBoxItem不同的是每一個TreeViewItem都繼承于HeaderedItemsControl類所以TreeViewItem是一個列表型的容器(而ListBoxItem是內(nèi)容型的容器)。

  在聲明TreeViewItem的數(shù)據(jù)模板時也與ListBoxItem有所不同,它使用聲明數(shù)據(jù)模板。

  關(guān)于TreeView綁定數(shù)據(jù),及數(shù)據(jù)模板的使用的示例代碼如下所示:

  由于在樹中顯示數(shù)據(jù),所以使用了兩個嵌套的類型作為實(shí)例類,兩個實(shí)體類的代碼如下:

class MyClass:INotifyPropertyChanged
    {
        private string classname;
        private ObservableCollection<Stu> students;

        public string ClassName
        {
            get { return classname; }
            set
            {
                classname = value;
                OnPropertyChanged(new PropertyChangedEventArgs("ClassName"));
            }
        }

        public ObservableCollection<Stu> Students
        {
            get { return students; }
            set
            {
                students = value;
                OnPropertyChanged(new PropertyChangedEventArgs("Students"));
            }
        }

        #region INotifyPropertyChanged 成員
        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged!=null)
            {
                PropertyChanged(this, e);
            }
        }
        #endregion
    }

 

    class Stu:INotifyPropertyChanged
    {

        private int myid;
        private string mynames;
        private int myage;
        private string mysex;
        private string myaddress;

        public int id
        {
            get { return myid; }
            set
            {
                myid = value;
                OnPropertyChanged(new PropertyChangedEventArgs("id"));
            }
        }

        public string names
        {
            get { return mynames; }
            set
            {
                mynames = value;
                OnPropertyChanged(new PropertyChangedEventArgs("names"));
            }
        }

        public int age
        {
            get { return myage; }
            set
            {
                myage = value;
                OnPropertyChanged(new PropertyChangedEventArgs("age"));
            }
        }

        public string sex
        {
            get { return mysex; }
            set
            {
                mysex = value;
                OnPropertyChanged(new PropertyChangedEventArgs("sex"));
            }
        }

        public string address
        {
            get { return myaddress; }
            set
            {
                myaddress = value;
                OnPropertyChanged(new PropertyChangedEventArgs("address"));
            }
        }

 

        #region INotifyPropertyChanged 成員

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, e);
            }
        }

        #endregion
    }

 資源字典的XAML代碼如下所示:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WPF中的TreeView控件.MyDictionary"
    xmlns:local="clr-namespace:WPF中的TreeView控件">
    
    <ObjectDataProvider x:Key="MyDataBase"
                        ObjectType="{x:Type local:wangjundatabase}"
                        MethodName="GetAllStu"
                        IsAsynchronous="True">
    </ObjectDataProvider>
    
    <HierarchicalDataTemplate x:Key="treeviewtemplate"ItemsSource="{Binding Path=Students}">
        <Grid Background="White">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="abc"/>
            </Grid.ColumnDefinitions>
            <Border Margin="2"
                CornerRadius="3"
                Background="DarkGoldenrod">
                <StackPanel>
                    <TextBlock Text="{Binding Path=ClassName}" Margin="5"></TextBlock>
                </StackPanel>
            </Border>
        </Grid>
        <HierarchicalDataTemplate.ItemTemplate>
           <HierarchicalDataTemplate>
                <Grid Background="White">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" SharedSizeGroup="abcd"/>
                    </Grid.ColumnDefinitions>
                    <Border Margin="2"
                                    CornerRadius="3"
                                    Background="Chocolate">
                        <StackPanel>
                            <TextBlock Text="{Binding Path=id}" Margin="5,1,5,1"></TextBlock>
                            <TextBlock Text="{Binding Path=names}" Margin="5,1,5,1"></TextBlock>
                            <TextBlock Text="{Binding Path=age}" Margin="5,1,5,1"></TextBlock>
                            <TextBlock Text="{Binding Path=sex}" Margin="5,1,5,1"></TextBlock>
                            <TextBlock Text="{Binding Path=address}" Margin="5,1,5,1"></TextBlock>
                        </StackPanel>
                    </Border>
                </Grid>               
           </HierarchicalDataTemplate>
        </HierarchicalDataTemplate.ItemTemplate>
    </HierarchicalDataTemplate>
    
</ResourceDictionary>

  窗體XAML代碼如下所示:

<Window x:Class="WPF中的TreeView控件.Window1"
    xmlns=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x=
"http://schemas.microsoft.com/winfx/2006/xaml"
    Title=
"Window1" Height="600" Width="600" WindowStartupLocation="CenterScreen">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/MyDictionary/MyDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <TreeView Margin="10" ItemTemplate="{StaticResource treeviewtemplate}"
                  ItemsSource=
"{Binding Source={StaticResource MyDataBase}}"
                  SnapsToDevicePixels=
"True" Grid.IsSharedSizeScope="True">
            <TreeView.ItemContainerStyle>
                <Style TargetType="TreeViewItem">
                    <Setter Property="Padding" Value="0"/>
                </Style>
            </TreeView.ItemContainerStyle>
        </TreeView>
    </Grid>
</Window>

本文來自2sws的博客,原文地址:http://hi.baidu.com/wangjunwangjuna/blog/item/0cb1de16977f7509962b4320.html

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
WPF快速入門系列(7)
用WPF建的IPAD demo (內(nèi)附下載源碼)
WPF深入淺出話資源
C# WPF抽屜效果實(shí)現(xiàn)(C# WPF Material Design UI: Navigation Drawer & PopUp Menu)
WPF開發(fā)學(xué)生信息管理系統(tǒng)【W(wǎng)PF+Prism+MAH+WebApi】(一)
定義和使用字典資源
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服