Le réseau pour les développeurs >
Forums - Accueil
>
Windows Presentation Foundation (WPF)
>
Changing Cell Template in a ListView programatically
Changing Cell Template in a ListView programatically
- Hi all,
I´m working on an app. that uses TemplateResources to switch between differents ListViews according some conditions.
And, due the string that appears in one of the cells of the selected listView, i have to change the cell template from this:
<GridViewColumn >
<GridViewColumnHeader Content="Line Status" Tag="ReturnStatus.return_status_desc" Width="AUTO"/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Name="lineStatusLbl" Content="{Binding Path=ReturnStatus.return_status_desc}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
To a Link:
<GridViewColumn>
<GridViewColumnHeader Content="Line Status" Tag="ReturnStatus.return_status_desc" Width="AUTO" />
<GridViewColumn.CellTemplate>
<DataTemplate x:Key="sarasa">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0 15 0 15" Style="{StaticResource LinkButtonContainerStyle}">
<Hyperlink Name="lnkErrorsWarnings" Style="{StaticResource LinkButtonStyle}" IsEnabled="True">
<TextBlock Name="errorsWarningsText"
Style="{StaticResource LinkButtonContainerStyle}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{Binding Path=ReturnStatus.return_status_desc}">
</TextBlock>
</Hyperlink>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Does anyone have any idea how to do it?
Réponses
- Hello,
Use a DataTemplateSelector:
<GridViewColumn CellTemplateSelector="{DynamicResource YourTemplateSelector}"/>More info:
http://msdn.microsoft.com/en-us/library/system.windows.controls.datatemplateselector.aspx
Good Luck.
- Marqué comme réponseZhi-Xin YeMSFT, Modérateurdimanche 8 novembre 2009 16:50
Toutes les réponses
- Hello,
Use a DataTemplateSelector:
<GridViewColumn CellTemplateSelector="{DynamicResource YourTemplateSelector}"/>More info:
http://msdn.microsoft.com/en-us/library/system.windows.controls.datatemplateselector.aspx
Good Luck.
- Marqué comme réponseZhi-Xin YeMSFT, Modérateurdimanche 8 novembre 2009 16:50
- Yes, i finally found how to do it. I let my solution here, in case someone need to do something similar: First, i add two DataTemplates inside my grid_dataTemplate (Inside ListView.Resources):

