I am using datagrid in WPF. In one of the column i need to display dropdown values. When the value is selected from combobox i want it to become hyperlink so that users will click the like to open new page. Here the picture. In the column "FAULT CLA" combobox is shown. I want the selected number "2" in first row and number "3" in 2nd row to be shown as hyperlinks as shown in other cells.
Code which i am using
<DataGridTemplateColumn x:Name="FaultClass2" Header="Fault Class" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="FaultClass1">
<ComboBoxItem Content="1"></ComboBoxItem>
<ComboBoxItem Content="2"></ComboBoxItem>
<ComboBoxItem Content="3"></ComboBoxItem>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
If anybody have idea on how to do please help me.
Thank you!
EDIT:
I tried your answer. Please check the code below.
<DataGridTemplateColumn CellEditingTemplate="{StaticResource EditTemplate1}"
CellTemplate="{StaticResource NormalTemplate}">
</DataGridTemplateColumn>
<UserControl.Resources>
<DataTemplate x:Key="EditTemplate1">
<ComboBox x:Name="FaultClass1">
<ComboBoxItem Content="1"></ComboBoxItem>
<ComboBoxItem Content="2"></ComboBoxItem>
<ComboBoxItem Content="3"></ComboBoxItem>
</ComboBox>
</DataTemplate>
<DataTemplate x:Key="NormalTemplate">
<TextBlock Margin="2,6" >
<Hyperlink Click="Hyperlink_Click" ToolTip="RQ1 Access Rights Required">
<Run Text="{Binding Path=SelectedItem, ElementName=FaultClass1}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</UserControl.Resources>
And the output i got is
So again hyperlink is missing. Could you please suggest me whats need to improved in hyperlink code?
Also if i click on combo box in second row, first row combobox selection is getting cleared.
Could you please guide me.
Thank you!
EDIT 2
Hi Again,
I did the following code changes.
<UserControl.Resources>
<DataTemplate x:Key="EditTemplate1">
<ComboBox x:Name="FaultClass1"
ItemsSource="{Binding ElementName=DSMCal_UserContrl, Path=DataContext.FaultClasses}" SelectedItem="{Binding ElementName=DSMCal_UserContrl,Path=DataContext.SelectedFaultClass}">
</ComboBox>
</DataTemplate>
<DataTemplate x:Key="NormalTemplate">
<TextBlock Margin="2,6" >
<Hyperlink Click="Hyperlink_Click" ToolTip="RQ1 Access Rights Required">
<Run Text="{Binding ElementName=DSMCal_UserContrl,Path=DataContext.SelectedFaultClass}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</UserControl.Resources>
Selection and hyperlink works now. Please see the screen shot below.
But now the problem is its setting the selected value of first row combo to remaining rows also.
And in the editing cell hyperlink is shown once the focus is changed.
Could you please give me idea how to solve this.
Thank you very much!