Click here to Skip to main content
15,888,579 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# [modified] Pin
Alisaunder12-Aug-11 10:26
Alisaunder12-Aug-11 10:26 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0112-Aug-11 11:01
SledgeHammer0112-Aug-11 11:01 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# [modified] Pin
Alisaunder12-Aug-11 13:32
Alisaunder12-Aug-11 13:32 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
Alisaunder13-Aug-11 11:25
Alisaunder13-Aug-11 11:25 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0113-Aug-11 11:49
SledgeHammer0113-Aug-11 11:49 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
Alisaunder13-Aug-11 15:09
Alisaunder13-Aug-11 15:09 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0113-Aug-11 15:35
SledgeHammer0113-Aug-11 15:35 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
Alisaunder14-Aug-11 14:36
Alisaunder14-Aug-11 14:36 
This is what I came up with

C#
using System;
using System.Data;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Manufactured_Housing_Manager
{
    public class Contact : INotifyPropertyChanged
    {
        private string _name = String.Empty;
        private int _id = 0;

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }  

        public string Name
        {
            get { return this._name; }

            set
            {
                if (value != this._name)
                {
                    this._name = value;
                    NotifyPropertyChanged("Name");
                }
            }  
        }

        public int Id
        {
            get { return this._id; }
            
            set
            {
                if (value != this._id)
                {
                    this._id = value;
                    NotifyPropertyChanged("Id");
                }
            }  
        }

        public Contact()
        {
        }

        public Contact(string name, int id)
        {
            _name = name;
            _id = id;
        }
    } 
}


My Xaml code is

HTML
<HierarchicalDataTemplate x:Key="ChildTemplate">
    <StackPanel Orientation="Horizontal">
        <Image x:Name="img2" Width="16"  Height="16" Stretch="Fill" Source="Images\closedfolder16.png" />
        <TextBlock Text="{Binding Path=Index}" Margin="5,0" ToolTip="{Binding Path=Index}"/>
    </StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="MyTreeViewStyle"
                          ItemsSource="{Binding Path=Contacts}"
                          ItemTemplate="{StaticResource ChildTemplate}">
    <!-- Display the Index by showing it's Index string -->
    <StackPanel Orientation="Horizontal">
        <Image x:Name="img" Width="16" Height="16" Stretch="Fill" Source="Images\closedfolder16.png" />
        <TextBlock Text="{Binding Path=Name}" Margin="5,0" ToolTip="{Binding Path=Name}"/>
    </StackPanel>
</HierarchicalDataTemplate>


and the code Inside the UserControl is like this

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace Manufactured_Housing_Manager
{
    /// <summary>
    /// Interaction logic for Outlookbar.xaml
    /// </summary>
    public partial class Outlookbar : UserControl
    {        
        static public ObservableCollection<Contact> Contacts = new ObservableCollection<Contact>();

        public Outlookbar()
        {
            InitializeComponent();
            InitializeTreeview(); 
        }

        #region left, right, mid string functions

        public static string left(string param, int length)
        {
            //we start at 0 since we want to get the characters starting from the
            //left and with the specified length and assign it to a variable
            string result = param.Substring(0, length);
            //return the result of the operation
            return result;
        }

        public static string mid(string param, int startIndex, int length)
        {
            //start at the specified index in the string and get the number of
            //characters depending on the length and assign it to a variable
            string result = param.Substring(startIndex, length);
            //return the result of the operation
            return result;
        }

        public static string right(string param, int length)
        {
            //start at the index based on the length of the string minus
            //the specified length and assign it a variable
            string result = param.Substring(param.Length - length, length);
            //return the result of the operation
            return result;
        }

        #endregion

        private void InitializeTreeview()
        {
            Contacts.Add(new Contact("Davis, Adam T.", 1));
            Contacts.Add(new Contact("Zappa, Frank", 2));

            // This is where I need to add the code to populate the treeview with name data

 
            myTreeView.DataContext = Contacts;
        }

    }
}


In this way I can see the 2 contacts I have manually added but I still don't know how to get the base a-z stucture setup right in my Collection. also need to figure out how to only populate the treeview after I have opened the oledb database and populated the dataset.

This all works fine if I have everything in one class form but by having seperate usercontrols it's prving to be more difficult to do. If I had a static database to bind too it might be easier but I am allowing for user selected databases.
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
SledgeHammer0114-Aug-11 15:04
SledgeHammer0114-Aug-11 15:04 
GeneralRe: Accessing function on Usercontrol hosted from Window in MVVM and C# Pin
Alisaunder15-Aug-11 22:01
Alisaunder15-Aug-11 22:01 
Questionsiilverlight 4 - listbox to have Tag Pin
arkiboys12-Aug-11 4:32
arkiboys12-Aug-11 4:32 
AnswerRe: siilverlight 4 - listbox to have Tag Pin
#realJSOP12-Aug-11 6:32
mve#realJSOP12-Aug-11 6:32 
Questionsilverlight listbox - fill colour Pin
arkiboys12-Aug-11 4:24
arkiboys12-Aug-11 4:24 
AnswerRe: silverlight listbox - fill colour Pin
Mycroft Holmes12-Aug-11 23:44
professionalMycroft Holmes12-Aug-11 23:44 
GeneralRe: silverlight listbox - fill colour Pin
arkiboys13-Aug-11 22:10
arkiboys13-Aug-11 22:10 
QuestionWPF Webbrowser bot releasing PDF file -- Help Needed Pin
pal2ashish12-Aug-11 0:36
pal2ashish12-Aug-11 0:36 
AnswerRe: WPF Webbrowser bot releasing PDF file -- Help Needed Pin
Alisaunder12-Aug-11 14:14
Alisaunder12-Aug-11 14:14 
GeneralRe: WPF Webbrowser bot releasing PDF file -- Help Needed Pin
pal2ashish14-Aug-11 4:19
pal2ashish14-Aug-11 4:19 
AnswerRe: WPF Webbrowser bot releasing PDF file -- Help Needed Pin
Oludayo Alli15-Aug-11 23:58
Oludayo Alli15-Aug-11 23:58 
GeneralRe: WPF Webbrowser bot releasing PDF file -- Help Needed Pin
pal2ashish28-Aug-11 22:44
pal2ashish28-Aug-11 22:44 
GeneralRe: WPF Webbrowser bot releasing PDF file -- Help Needed Pin
Alisaunder12-Sep-11 6:08
Alisaunder12-Sep-11 6:08 
GeneralRe: WPF Webbrowser bot releasing PDF file -- Help Needed Pin
pal2ashish12-Sep-11 19:16
pal2ashish12-Sep-11 19:16 
QuestionVector editor Pin
transoft11-Aug-11 5:05
transoft11-Aug-11 5:05 
QuestionOnApplyTemplate & designer mode Pin
SledgeHammer0110-Aug-11 6:50
SledgeHammer0110-Aug-11 6:50 
AnswerRe: OnApplyTemplate & designer mode Pin
SledgeHammer0110-Aug-11 6:55
SledgeHammer0110-Aug-11 6:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.