title: Using a View as a Data Template
body: <p>I am using the MVVM structure for our application. I have added the view as a data template to a grid (Developer Express DXGrid).</p>
  
  <pre><code>&lt;DataTemplate x:Key="cardTemplate"&gt;
       &lt;ui:MediaEnquiryParticipantView x:Name="mediaEnquiryParticipantView"/&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>Now, my problem is that i want that View(MediaEnquiryParticipantView) to represent 1 row of a table.</p>
  
  <p>How do i approach my problem? </p>
  
  <hr>
  
  <pre><code>&lt;dxg:GridControl Name="grdParticipants"
                       Grid.Row="0"
                       Height="Auto" Width="Auto"
                       MaxHeight="5000"
                       VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                       AutoPopulateColumns="True"
                       DataSource="{Binding Path=MediaEnquiryParticipantList,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                       MouseDoubleClick="grdParticipants_MouseDoubleClick"&gt;
              &lt;dxg:GridControl.Resources&gt;
                  &lt;DataTemplate x:Key="headerTemplateFullName"&gt;
                      &lt;StackPanel Orientation="Horizontal"&gt;
                          &lt;TextBlock Text="{Binding Path=Data.caUser.UserName}" /&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
                  &lt;DataTemplate x:Key="cardTemplate"&gt;
                      &lt;ui:MediaEnquiryParticipantView x:Name="mediaEnquiryParticipantView" MediaEnquiryID="{Binding Path=Data.MediaEnquiryID}"/&gt;
                  &lt;/DataTemplate&gt;
              &lt;/dxg:GridControl.Resources&gt;
              &lt;dxg:GridControl.Columns&gt;
                  &lt;dxg:GridColumn FieldName="UserName" Width="150" AllowColumnFiltering="False"/&gt;
                  &lt;dxg:GridColumn FieldName="CanResolve" Width="150" AllowColumnFiltering="False"/&gt;
              &lt;/dxg:GridControl.Columns&gt;
              &lt;dxg:GridControl.View&gt;
                  &lt;dxg:CardView x:Name="cardView"                                  
                                CardHeaderTemplate="{DynamicResource headerTemplateFullName}"
                                CardTemplate="{DynamicResource cardTemplate}"&gt;
                      &lt;dxg:CardView.RowCellMenuCustomizations&gt;
                          &lt;dxb:BarButtonItemLink BarItemName="btnDelete" /&gt;
                      &lt;/dxg:CardView.RowCellMenuCustomizations&gt;
                  &lt;/dxg:CardView&gt;
              &lt;/dxg:GridControl.View&gt;
          &lt;/dxg:GridControl&gt;
  </code></pre>
  
  <hr>
  
  <p>The grid above is displaying "MediaEnquiryParticipantView" in a cardview form. The grid in part of "MediaEnquiryParticipantsView" I have separate view models for each. </p>
  
  <p>My code for MediaEnquiryParticipantViewModel:</p>
  
  <pre><code>public class MediaEnquiryParticipantViewModel : ViewModelBase
  {
      #region Fields
  
      private IQueryable&lt;caUser&gt; userList;
  
      #endregion Fields
  
      #region Constructors
  
      public MediaEnquiryParticipantViewModel(SessionContext sessionContext, NavigationItem navigationItem, MediaEnquiryViewModel mediaEnquiryViewModel, Mediator mediator)
          : base(mediator)
      {
          SessionContext = sessionContext;
          NavigationItem = navigationItem;
      }
  
      #endregion Constructors
  
      #region Properties
  
      public IQueryable&lt;caUser&gt; UserList
      {
          get
          {
              if (userList == null)
              {
                  userList = GetUserList();
              }
              return userList;
          }
          set
          {
              userList = value;
              OnPropertyChanged("UserList");
          }
      }
  
      #endregion Properties
  
      #region Methods
  
      private IQueryable&lt;caUser&gt; GetUserList()
      {
          IQueryable&lt;caUser&gt; list = (from u in ((Chase_Media_Pro_Entity_Model)this.NavigationItem.ObjectContext).caUser
                                     select u);
  
          return list;
      }
  
      #endregion Methods
  }
  </code></pre>
  
  <hr>
  
  <p>The userList is for the combo box in MediaEnquiryParticipantView. </p>