Click here to Skip to main content
15,887,214 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: WPF Text box style Pin
Bernhard Hiller26-Sep-13 21:59
Bernhard Hiller26-Sep-13 21:59 
AnswerRe: WPF Text box style Pin
Abhinav S27-Sep-13 22:59
Abhinav S27-Sep-13 22:59 
GeneralRe: WPF Text box style Pin
Yogi_vns0072-Oct-13 18:46
Yogi_vns0072-Oct-13 18:46 
GeneralRe: WPF Text box style Pin
Mycroft Holmes2-Oct-13 22:55
professionalMycroft Holmes2-Oct-13 22:55 
QuestionMEF and ActiveX control in .NET Pin
Raajikiwi24-Sep-13 19:20
Raajikiwi24-Sep-13 19:20 
QuestionHow to print & preview Radgridview row per page in wpf Pin
ramkie24-Sep-13 18:42
ramkie24-Sep-13 18:42 
AnswerRe: How to print & preview Radgridview row per page in wpf Pin
Abhinav S24-Sep-13 20:39
Abhinav S24-Sep-13 20:39 
QuestionWPF DataGrid with DataGrid in RowDetailsTemplate Pin
Kevin Marois24-Sep-13 6:18
professionalKevin Marois24-Sep-13 6:18 
My previous post about detecting property changes in the VM wasn't in depth enough, so I'm posting this

I have a grid of Jobs. Each job can have one or more employees.

The DataGrid's RowDetailsTemplate contains another grid to show the employees. So to parent grid is bound to a list of Jobs. The inner grid is bound to a list of Employees that is on the Job model.

The Job Model:

public class Job : _Base
{
    private string _JobName = string.Empty;
    public string JobName
    {
        get { return _JobName; }
        set 
        {
            if (_JobName != value)
            {
                _JobName = value;
                RaisePropertyChanged("JobName");
            }
        }
    }

    private string _JobNumber = string.Empty;
    public string JobNumber
    {
        get { return _JobNumber; }
        set
        {
            if (_JobNumber != value)
            {
                _JobNumber = value;
                RaisePropertyChanged("JobNumber");
            }
        }
    }

    private ObservableCollection<Employee> _Employees;
    public ObservableCollection<Employee> Employees
    {
        get { return _Employees; }
        set
        {
            if (_Employees != value)
            {
                if (_Employees != value)
                {
                    _Employees = value;
                    RaisePropertyChanged("Employees");
                }
            }
        }
    }

    private Employee _SelectedEmployee;
    public Employee SelectedEmployee
    {
        get { return _SelectedEmployee; }
        set
        {
            if (_SelectedEmployee != value)
            {
                if (_SelectedEmployee != value)
                {
                    _SelectedEmployee = value;
                    RaisePropertyChanged("SelectedEmployee");
                }
            }
        }
    }

    public Job()
    {
        Employees = new ObservableCollection<Employee>();
    }
}


The Employee model

public class Employee : _Base
{
    private string _EmployeeName = string.Empty;
    public string EmployeeName
    {
        get { return _EmployeeName; }
        set
        {
            if (_EmployeeName != value)
            {
                _EmployeeName = value;
                RaisePropertyChanged("EmployeeName");
            }
        }
    }

    private bool _IsChecked = false;
    public bool IsChecked
    {
        get { return _IsChecked; }
        set
        {
            if (_IsChecked != value)
            {
                _IsChecked = value;
                RaisePropertyChanged("IsChecked");
            }
        }
    }
}       


The XAML

<DataGrid ItemsSource="{Binding Jobs}"
            SelectedItem="{Binding SelectedJob}"
            AutoGenerateColumns="False">

    <DataGrid.Columns>
        <DataGridTextColumn Header="Job Name" Binding="{Binding JobName}" />
        <DataGridTextColumn Header="Job Number" Binding="{Binding JobNumber}" />
    </DataGrid.Columns>

    <DataGrid.RowDetailsTemplate>
        <DataTemplate>

            <StackPanel Orientation="Vertical">

                <DataGrid ItemsSource="{Binding Employees}"
                            SelectedItem="{Binding SelectedEmployee}"
                            AutoGenerateColumns="False">

                    <DataGrid.Columns>
                        <DataGridCheckBoxColumn Binding="{Binding IsChecked}"/>
                        <DataGridTextColumn Binding="{Binding EmployeeName}"/>
                    </DataGrid.Columns>

                </DataGrid>

                <Button Margin="5"
                        Height="23"
                        Width="75"
                        HorizontalAlignment="Left"
                        Content="Remove"/>

            </StackPanel>


        </DataTemplate>
    </DataGrid.RowDetailsTemplate>

</DataGrid>


The MainWindowViewModel

public class MainWindowViewModel : _Base
{
    private ObservableCollection<Job> _Jobs;
    public ObservableCollection<Job> Jobs
    {
        get { return _Jobs; }
        set 
        {
            if (_Jobs != value)
            {
                if (_Jobs != value)
                {
                    _Jobs = value;
                    RaisePropertyChanged("Jobs");
                }
            }
        }
    }

    private Job _SelectedJob;
    public Job SelectedJob
    {
        get { return _SelectedJob; }
        set
        {
            if (_SelectedJob != value)
            {
                if (_SelectedJob != value)
                {
                    _SelectedJob = value;
                    RaisePropertyChanged("SelectedJob");
                }
            }
        }
    }

    public MainWindowViewModel()
    {
        this.PropertyChanged += new PropertyChangedEventHandler(MainWindowViewModel_PropertyChanged);
    }

    void MainWindowViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        if (e.PropertyName.Trim().ToLower() == "ischecked")
        {
            int x = 1;
        }
    }
}


I have a couple of questions:

1) The SelectedEmployee property on the Job model does not fire when I click an employee in the inner grid.

2) The MainWindowViewModel_PropertyChanged does not fire when an employee is selected.

3) Notice the button below the inner grid. How do I bind its command to MainWindowVM?


If it's not broken, fix it until it is

QuestionWPF MVVM Determine When Property On Model Changes Pin
Kevin Marois24-Sep-13 5:11
professionalKevin Marois24-Sep-13 5:11 
AnswerRe: WPF MVVM Determine When Property On Model Changes Pin
Pete O'Hanlon24-Sep-13 5:27
mvePete O'Hanlon24-Sep-13 5:27 
GeneralRe: WPF MVVM Determine When Property On Model Changes Pin
Kevin Marois24-Sep-13 5:29
professionalKevin Marois24-Sep-13 5:29 
GeneralRe: WPF MVVM Determine When Property On Model Changes Pin
Pete O'Hanlon24-Sep-13 5:44
mvePete O'Hanlon24-Sep-13 5:44 
GeneralRe: WPF MVVM Determine When Property On Model Changes Pin
Kevin Marois24-Sep-13 5:45
professionalKevin Marois24-Sep-13 5:45 
GeneralRe: WPF MVVM Determine When Property On Model Changes Pin
Pete O'Hanlon24-Sep-13 7:04
mvePete O'Hanlon24-Sep-13 7:04 
GeneralRe: WPF MVVM Determine When Property On Model Changes Pin
SledgeHammer0124-Sep-13 8:21
SledgeHammer0124-Sep-13 8:21 
GeneralRe: WPF MVVM Determine When Property On Model Changes Pin
Pete O'Hanlon24-Sep-13 8:24
mvePete O'Hanlon24-Sep-13 8:24 
GeneralRe: WPF MVVM Determine When Property On Model Changes Pin
Mycroft Holmes24-Sep-13 21:25
professionalMycroft Holmes24-Sep-13 21:25 
QuestionHow to create multi focus in Surface application so multiple users can use application togather on sur 40 Pin
sacpundir15-Sep-13 21:29
professionalsacpundir15-Sep-13 21:29 
Questiona question about MVVM Pin
lijizhe12-Sep-13 22:38
lijizhe12-Sep-13 22:38 
AnswerRe: a question about MVVM Pin
Richard MacCutchan12-Sep-13 23:56
mveRichard MacCutchan12-Sep-13 23:56 
QuestionHow to create appointment in radscheduleview programatically from another window Pin
ramkie12-Sep-13 1:42
ramkie12-Sep-13 1:42 
AnswerRe: How to create appointment in radscheduleview programatically from another window Pin
Pete O'Hanlon12-Sep-13 2:55
mvePete O'Hanlon12-Sep-13 2:55 
QuestionWPF/MVVM App On WIndows 8 Tablet - Touch Doesn't Work Pin
Kevin Marois11-Sep-13 6:02
professionalKevin Marois11-Sep-13 6:02 
AnswerRe: WPF/MVVM App On WIndows 8 Tablet - Touch Doesn't Work Pin
Punamchand Dhuppad19-Sep-13 18:10
professionalPunamchand Dhuppad19-Sep-13 18:10 
QuestionWPF DataGrid with Bands Pin
Kevin Marois10-Sep-13 11:50
professionalKevin Marois10-Sep-13 11:50 

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.