Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

What am I missing here ?

$
0
0

Hi Experts,

This is what im trying to do.

I have created a user control with DataGrid coltrol which implements INotifyPropertyChanged. Added a Textblock to display the title of the grid. text property of the Textblock is binded to a CLR title property within the same control.

I have added this unse control to another XAML view and binded a list of items and the grid populates it correctly. Also i'm setting the title of the control within the calling xaml window but I dont see the title.

User Control's Title property 

        private string title;
        /// <summary>
        /// Get and Set the Title of the Control
        /// </summary>
        public string Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
                PropertyValueChanged("Title");
            }
        }

How the list is generated for binding

public class StaffInformation
    {
        public enum Genders
        {
            Unknown,
            Male,
            Female,
        }

        [HeaderName("First Name"), ColumnIndex("0")]
        public string FirstName { get; set; }

        [HeaderName("Last Name"), ColumnIndex("2")]
        public string LastName { get; set; }

        [HeaderName("Email Address"), ColumnIndex("3")]
        public string Email { get; set; }

        //[HeaderName("Gender"), ColumnIndex("1")]
        //public Genders Gender { get; set; }

        [HeaderName("City"), ColumnIndex("4")]
        public string City { get; set; }

        [HeaderName("Profession"), ColumnIndex("5")]
        public string Profession { get; set; }

    }

    public class BindingCollection
    {
        public List<StaffInformation> StaffDetails
        {
            get
            {
                List<StaffInformation> staffInfo = new List<StaffInformation>();
                staffInfo.Add(new StaffInformation { City = "Colombo", Email = "kur@gmail.com", FirstName = "Kuru", LastName = "Thiya", Profession = "Eng" });

                return staffInfo;
            }
        }

        public string Title
        {
            get
            {
                return "Staff Details";
            }
        }
    }

How the DataContext is set to user control from calling xaml view's code behind

private void PopulateDataGrid() { BindingCollection bc = new BindingCollection();

//Setting the datacontext of user control StaffDetailsGrid.DataContext = bc.StaffDetails; StaffDetailsGrid.Title = bc.Title; }




Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>