Click here to Skip to main content
15,897,704 members
Articles / Web Development / ASP.NET

Cascading Selection the MVC Way

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
29 Mar 2013CPOL12 min read 26K   509   25  
How to easily implement cascading selection the MVC way and leverage cached static data.
<Window xmlns:xom="clr-namespace:Xomega.Framework;assembly=Xomega.Framework"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:l="clr-namespace:AdventureWorks.Client.Objects;assembly=AdventureWorks.Client.Objects"
        x:Class="AdventureWorks.Client.WPF.EmployeeDetails"
        Title="Employee Details"
        Height="640"
        Width="640">
   <Grid Margin="10">
      <Grid.ColumnDefinitions>
         <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
         <RowDefinition Height="*"/>
         <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
      <Button Grid.Row="1" Name="btnClose" HorizontalAlignment="Right"
              VerticalAlignment="Top"
              Width="75"
              Click="btnClose_Click">_Close</Button>
      <Button Grid.Row="1" Name="btnSave" HorizontalAlignment="Right" VerticalAlignment="Top"
              Margin="0,0,90,0"
              Width="75"
              Click="btnSave_Click">_Save</Button>
      <Button Grid.Row="1" Name="btnDelete" HorizontalAlignment="Left"
              VerticalAlignment="Top"
              Margin="0,0,0,0"
              Width="75"
              Click="btnDelete_Click"
              IsEnabled="False">_Delete</Button>
      <Grid Name="pnlMain">
         <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
         </Grid.ColumnDefinitions>
         <Label Name="lblEmployeeId" Style="{StaticResource LabelStyle}" Grid.Row="0"
                Grid.Column="0">_Employee Id:</Label>
         <TextBox Grid.Row="0" Grid.Column="1" Name="ctlEmployeeId"
                  xom:Property.Name="{x:Static l:EmployeeObject.EmployeeId}"
                  xom:Property.Label="{Binding ElementName=lblEmployeeId}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblNationalIDNumber" Style="{StaticResource LabelStyle}" Grid.Row="1"
                Grid.Column="0">_National ID Number:</Label>
         <TextBox Grid.Row="1" Grid.Column="1" Name="ctlNationalIDNumber"
                  xom:Property.Name="{x:Static l:EmployeeObject.NationalIDNumber}"
                  xom:Property.Label="{Binding ElementName=lblNationalIDNumber}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblLogin" Style="{StaticResource LabelStyle}" Grid.Row="2"
                Grid.Column="0">_Login:</Label>
         <TextBox Grid.Row="2" Grid.Column="1" Name="ctlLogin"
                  xom:Property.Name="{x:Static l:EmployeeObject.Login}"
                  xom:Property.Label="{Binding ElementName=lblLogin}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblManager" Style="{StaticResource LabelStyle}" Grid.Row="3"
                Grid.Column="0">_Manager:</Label>
         <TextBox Grid.Row="3" Grid.Column="1" Name="ctlManager"
                  xom:Property.Name="{x:Static l:EmployeeObject.Manager}"
                  xom:Property.Label="{Binding ElementName=lblManager}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblTitle" Style="{StaticResource LabelStyle}" Grid.Row="4"
                Grid.Column="0">_Title:</Label>
         <TextBox Grid.Row="4" Grid.Column="1" Name="ctlTitle"
                  xom:Property.Name="{x:Static l:EmployeeObject.Title}"
                  xom:Property.Label="{Binding ElementName=lblTitle}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblBirthDate" Style="{StaticResource LabelStyle}" Grid.Row="5"
                Grid.Column="0">_Birth Date:</Label>
         <TextBox Grid.Row="5" Grid.Column="1" Name="ctlBirthDate"
                  xom:Property.Name="{x:Static l:EmployeeObject.BirthDate}"
                  xom:Property.Label="{Binding ElementName=lblBirthDate}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblMaritalStatus" Style="{StaticResource LabelStyle}" Grid.Row="6"
                Grid.Column="0">_Marital Status:</Label>
         <ComboBox Grid.Row="6" Grid.Column="1" Name="ctlMaritalStatus"
                   xom:Property.Name="{x:Static l:EmployeeObject.MaritalStatus}"
                   xom:Property.Label="{Binding ElementName=lblMaritalStatus}"
                   Style="{StaticResource ControlStyle}"/>
         <Label Name="lblGender" Style="{StaticResource LabelStyle}" Grid.Row="7"
                Grid.Column="0">_Gender:</Label>
         <ComboBox Grid.Row="7" Grid.Column="1" Name="ctlGender"
                   xom:Property.Name="{x:Static l:EmployeeObject.Gender}"
                   xom:Property.Label="{Binding ElementName=lblGender}"
                   Style="{StaticResource ControlStyle}"/>
         <Label Name="lblHireDate" Style="{StaticResource LabelStyle}" Grid.Row="8"
                Grid.Column="0">_Hire Date:</Label>
         <TextBox Grid.Row="8" Grid.Column="1" Name="ctlHireDate"
                  xom:Property.Name="{x:Static l:EmployeeObject.HireDate}"
                  xom:Property.Label="{Binding ElementName=lblHireDate}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblSalariedFlag" Style="{StaticResource LabelStyle}" Grid.Row="9"
                Grid.Column="0">_Salaried Flag:</Label>
         <CheckBox Grid.Row="9" Grid.Column="1" Name="ctlSalariedFlag"
                   xom:Property.Name="{x:Static l:EmployeeObject.SalariedFlag}"
                   xom:Property.Label="{Binding ElementName=lblSalariedFlag}"
                   Style="{StaticResource ControlStyle}"/>
         <Label Name="lblVacationHours" Style="{StaticResource LabelStyle}" Grid.Row="0"
                Grid.Column="2">_Vacation Hours:</Label>
         <TextBox Grid.Row="0" Grid.Column="3" Name="ctlVacationHours"
                  xom:Property.Name="{x:Static l:EmployeeObject.VacationHours}"
                  xom:Property.Label="{Binding ElementName=lblVacationHours}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblSickLeaveHours" Style="{StaticResource LabelStyle}" Grid.Row="1"
                Grid.Column="2">_Sick Leave Hours:</Label>
         <TextBox Grid.Row="1" Grid.Column="3" Name="ctlSickLeaveHours"
                  xom:Property.Name="{x:Static l:EmployeeObject.SickLeaveHours}"
                  xom:Property.Label="{Binding ElementName=lblSickLeaveHours}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblCurrentFlag" Style="{StaticResource LabelStyle}" Grid.Row="2"
                Grid.Column="2">_Current Flag:</Label>
         <CheckBox Grid.Row="2" Grid.Column="3" Name="ctlCurrentFlag"
                   xom:Property.Name="{x:Static l:EmployeeObject.CurrentFlag}"
                   xom:Property.Label="{Binding ElementName=lblCurrentFlag}"
                   Style="{StaticResource ControlStyle}"/>
         <Label Name="lblRowguid" Style="{StaticResource LabelStyle}" Grid.Row="3"
                Grid.Column="2">_Rowguid:</Label>
         <TextBox Grid.Row="3" Grid.Column="3" Name="ctlRowguid"
                  xom:Property.Name="{x:Static l:EmployeeObject.Rowguid}"
                  xom:Property.Label="{Binding ElementName=lblRowguid}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblModifiedDate" Style="{StaticResource LabelStyle}" Grid.Row="4"
                Grid.Column="2">_Modified Date:</Label>
         <TextBox Grid.Row="4" Grid.Column="3" Name="ctlModifiedDate"
                  xom:Property.Name="{x:Static l:EmployeeObject.ModifiedDate}"
                  xom:Property.Label="{Binding ElementName=lblModifiedDate}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblFirstName" Style="{StaticResource LabelStyle}" Grid.Row="5"
                Grid.Column="2">_First Name:</Label>
         <TextBox Grid.Row="5" Grid.Column="3" Name="ctlFirstName"
                  xom:Property.Name="{x:Static l:ContactObject.FirstName}"
                  xom:Property.ChildObject="{x:Static l:EmployeeObject.Contact}"
                  xom:Property.Label="{Binding ElementName=lblFirstName}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblMiddleName" Style="{StaticResource LabelStyle}" Grid.Row="6"
                Grid.Column="2">_Middle Name:</Label>
         <TextBox Grid.Row="6" Grid.Column="3" Name="ctlMiddleName"
                  xom:Property.Name="{x:Static l:ContactObject.MiddleName}"
                  xom:Property.ChildObject="{x:Static l:EmployeeObject.Contact}"
                  xom:Property.Label="{Binding ElementName=lblMiddleName}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblLastName" Style="{StaticResource LabelStyle}" Grid.Row="7"
                Grid.Column="2">_Last Name:</Label>
         <TextBox Grid.Row="7" Grid.Column="3" Name="ctlLastName"
                  xom:Property.Name="{x:Static l:ContactObject.LastName}"
                  xom:Property.ChildObject="{x:Static l:EmployeeObject.Contact}"
                  xom:Property.Label="{Binding ElementName=lblLastName}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblEmailAddress" Style="{StaticResource LabelStyle}" Grid.Row="8"
                Grid.Column="2">_Email Address:</Label>
         <TextBox Grid.Row="8" Grid.Column="3" Name="ctlEmailAddress"
                  xom:Property.Name="{x:Static l:ContactObject.EmailAddress}"
                  xom:Property.ChildObject="{x:Static l:EmployeeObject.Contact}"
                  xom:Property.Label="{Binding ElementName=lblEmailAddress}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblPhone" Style="{StaticResource LabelStyle}" Grid.Row="9"
                Grid.Column="2">_Phone:</Label>
         <TextBox Grid.Row="9" Grid.Column="3" Name="ctlPhone"
                  xom:Property.Name="{x:Static l:ContactObject.Phone}"
                  xom:Property.ChildObject="{x:Static l:EmployeeObject.Contact}"
                  xom:Property.Label="{Binding ElementName=lblPhone}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Name="lblPayHistory" Grid.Row="10" Grid.ColumnSpan="4">Pay History:</Label>
         <ListView Grid.Row="11" Grid.ColumnSpan="4" Name="gridPayHistory">
            <ListView.View>
               <GridView>
                  <GridView.Columns>
                     <GridViewColumn Header="Pay Frequency">
                        <GridViewColumn.CellTemplate>
                           <DataTemplate>
                              <TextBlock xom:Property.Name="{x:Static l:EmployeePayHistory.PayFrequency}"/>
                           </DataTemplate>
                        </GridViewColumn.CellTemplate>
                     </GridViewColumn>
                     <GridViewColumn Header="Rate">
                        <GridViewColumn.CellTemplate>
                           <DataTemplate>
                              <TextBlock xom:Property.Name="{x:Static l:EmployeePayHistory.Rate}"/>
                           </DataTemplate>
                        </GridViewColumn.CellTemplate>
                     </GridViewColumn>
                     <GridViewColumn Header="Rate Change Date">
                        <GridViewColumn.CellTemplate>
                           <DataTemplate>
                              <TextBlock xom:Property.Name="{x:Static l:EmployeePayHistory.RateChangeDate}"/>
                           </DataTemplate>
                        </GridViewColumn.CellTemplate>
                     </GridViewColumn>
                  </GridView.Columns>
               </GridView>
            </ListView.View>
         </ListView>
      </Grid>
   </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Xomega.Net
United States United States
Xomega Team is striving to increase productivity and development quality by utilizing Model Driven Development coupled with Code Generation and the best design practices for application development.
We provide MDD tools, code generators and frameworks for Visual Studio and .Net development.
Visit us at http://www.xomega.net
This is a Organisation

1 members

Comments and Discussions