All pastes #2134306 Raw Edit

Something

public text v1 · immutable
#2134306 ·published 2012-03-31 15:36 UTC
rendered paste body
XAML:


    <Window.Resources>
        <HierarchicalDataTemplate DataType="{x:Type Model:DirectoryItem}" ItemsSource="{Binding Items}">
            <TextBlock Text="{Binding Path=Name}" ToolTip="{Binding Path=Path}" />
        </HierarchicalDataTemplate>
        <DataTemplate DataType="{x:Type Model:FileItem}">
            <TextBlock Text="{Binding Path=Name}" ToolTip="{Binding Path=Path}" />
        </DataTemplate>
    </Window.Resources>
    
...


            <!-- Treeview for displaying the file list -->
            <TreeView Name="myView" Grid.Row="1" Grid.Column="0" Margin="5"
                      MinHeight="20" ItemsSource="{Binding}" ScrollViewer.VerticalScrollBarVisibility="Auto"
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled" VerticalAlignment="Stretch">
                <TreeView.ItemContainerStyle>
                    <Style TargetType="TreeViewItem">
                        <Setter Property="IsExpanded" Value="True" />
                    </Style>
                </TreeView.ItemContainerStyle>
            </TreeView>
            





C#

        // event
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

        // Model object
        public LogicClass Model { get; set; }

        // Binding properties
        public List<Item> MyList { get; set; }

        public string MyFileSearch  
        {
            get
            {
                return Model.FileSearch();
            }

            set
            {
                Model.FileSearch(value);
                Thread t = new Thread(WindowMyListAsynchronous);
                t.Start();
            }
        }

        public AppWindow()
        {
            InitializeComponent();
            Model = new LogicClass();

            // Populate window (file list, file search)
            WindowMyList();
            WindowMySearch();

            // Set the data context to the view model
            DataContext = this;
        }

        // Everything that will change what is seen in the window
        public void WindowMyList()
        {
            MyList = Model.UpdateList("C:\\");
            myView.ItemsSource = MyList;
        }

        public void WindowMyListAsynchronous()
        {
            MyList = Model.UpdateList("C:\\");
            OnPropertyChanged("MyList");
        }