I have an abstract object called Applicant and two different types of objects that inherit from Applicant called Business and Individual. So I have three classes that look like this:
public abstract class Applicant
{
...
}
public class Individual : Applicant
{
...
}
public class Business : Applicant
{
...
}
Now in the DataGrid I want to show all the details of Applicant object. When you choose a row I want to show details of either the business or individual as a internal grid. Something like this
<DataGrid>
<DataGrid.Columns>
<!--Show different columns -->
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<!--Show if Individual -->
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn Header="First Name" ... />
<DataGridTextColumn Header="Last Name" ... />
</DataGrid.Columns>
</DataGrid>
<!--Show if business -->
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn Header="Business Name" ... />
<DataGridTextColumn Header="Tax id" ... />
</DataGrid.Columns>
</DataGrid>
</DataGrid.RowDetailsTemplate>
</DataGrid>
Now I'm not sure if I need to use a 开发者_StackOverflow中文版Triggers or Behaviors to accomplish this? Thanks for everyones help! FYI I'm using Silverlight 4.0 with Prism.
I'd user use neither:
- Have two views (grids) - one renders Individual details, another renders Business details.
- Define a ContentControl inside of RowDetailsTemplate and make it a region.
- Then handle SelectedApplicant change in your ViewModel for the main grid so that it would activate the proper view in the region depending on the type of selected applicant.
I don't think you need neither behaviours nor triggers but databinding. There is a great simple intro what databinding is in msdn documentation.
The thing that is unique in your cituation is that you don't have one but two different DataTemplates
for your datagrid and you need to change them on the fly. I found a blogpost and a silverlight.net forum thread about that subject: Changing Data-Templates at run-time from the VM and forum.
First one uses some pretty simple codebehind logic and the one in the forum does the same thing using an IValueConverter
.
精彩评论