0

Here is part of my UI: http://imgur.com/MtXSCnL

In the Department List, I have a list of Department objects (I am using the MVVM pattern). I access these objects through an Observable collection in the DepartmentViewModel.

I am using the Entity Framework to link with my database and I am trying to do the following:

I am binding the SelectedItem in the Department list to display information in the Department Groupbox. The problem occurs when I try to bind the department's Foreign Key (Office in this case) to the Combobox. I have an Office property of type Office in my Department viewmodel however I would like to display the OfficeName property of the Office object in the combobox and be able to modify and save changes to Department (the logic for this is already done).

How do I bind a property of type Office to display the OfficeName in the combobox?

DepartmentViewModel:

   /// <summary>
    /// Office
    /// </summary>
    private const string OfficePropertyName = "Office";
    public Office Office
    {
        get { return _newDepartment.Office; }
        set
        {
            _newDepartment.Office = value;
            OnPropertyChanged(OfficePropertyName);
        }
    }

    private ObservableCollection<Office> _OfficeList;

    private const string OfficeListPropertyName = "OfficeList";
    public ObservableCollection<Office> OfficeList
    {
        get
        {
            return _OfficeList;
        }
        set
        {
            _OfficeList = value;
            OnPropertyChanged(OfficeListPropertyName);
        }
    }

DepartmentView

            <ListBox Grid.Row="0"
                 ItemsSource="{Binding DepartmentList}" 
                 DisplayMemberPath="DepartmentName"
                 SelectedItem="{Binding SelectedDepartment}"/>


            <StackPanel Grid.Row="1" Grid.Column="2">
                <TextBox Margin="10,10" Text="{Binding SelectedDepartment.DepartmentName}" />
                <TextBox Margin="10,10" Text="{Binding SelectedDepartment.Supervisor}" />

                <!-- List of all Office...here is where I want to show the selected office from the selected item in department list -->
                <ComboBox Grid.Row="3" Grid.Column="1" Margin="10,10"
              ItemsSource="{Binding OfficeList}"
              DisplayMemberPath="OfficeName"
              SelectedItem="{Binding Office}" />

            </StackPanel>
4

0 回答 0