Hello,
I used a CellValuePresenter to display hyperlinks in the grid successfully after following examples in this forum. thx!
I need to optionally (based on another cell's value) show the hyperlink so some values will be hyperlinked and some will not in the same column that is using the cellvaluepresenter. Is this possible? Any examples would be helpful.
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="hyperlinkCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<TextBlock Margin="{TemplateBinding Padding}" VerticalAlignment="Center" HorizontalAlignment="Right">
<Hyperlink Click="Grid_CellClicked" Tag="{Binding}" >
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value}" HorizontalAlignment="Right"/>
</Hyperlink>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
...
<igDP:Field><igDP:Field.Settings>
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource ResourceKey=hyperlinkCell}">
Thank You!
Thanks Stefan for your reply. I have implemented it already using visibility property. Please have a look at the code below.
<toolkit:DataGridTemplateColumn x:Name="LinkOpptyID" Width="70"> <toolkit:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock> <Hyperlink Click="opptyLink_Click"> <TextBlock Text="{Binding OpportunityId}" Visibility="{Binding IsHyperlinkVisible, Converter={StaticResource boolToVisiConverter}}"></TextBlock> </Hyperlink> <TextBlock Text="{Binding OpportunityId}" Visibility="{Binding IsTextVisible, Converter={StaticResource boolToVisiConverter}}"></TextBlock> </TextBlock> </DataTemplate> </toolkit:DataGridTemplateColumn.CellTemplate> </toolkit:DataGridTemplateColumn>
Hello Arvind,
I have implemented the functionality Vlad suggested in the MS DataGrid.
Hope this helps you.
How can I have both hyperlink and Non-Hyperlinked text in same column in WPF Grid? Below is my XAML
<!--Added by v-arbabu on 01.25.2013 to have hyperlinks for OpptyID--> <toolkit:DataGridTemplateColumn x:Name="LinkOpptyID" Width="70"> <toolkit:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock> <Hyperlink Click="opptyLink_Click"> <TextBlock Text="{Binding OpportunityId}"></TextBlock> </Hyperlink> </TextBlock> </DataTemplate> </toolkit:DataGridTemplateColumn.CellTemplate> </toolkit:DataGridTemplateColumn> <!--Ends Here-->
Vlad,
That was perfect. It exactly fixed my issue. Now, some items in the column are hyperlinked and others are not. The only change I made is instead of Binding the trigger to Cells I bound to the DataItem to get the value I needed as I am no longer displaying the column that I was checking for. With that change your code worked perfectly.
You might achieve this using two textblock controls in the template and datatrigger to switch the visibility based on another cell's value (in my case boolean):
<Grid>
<TextBlock Margin="{TemplateBinding Padding}" VerticalAlignment="Center"
Visibility="Visible" x:Name="txt1">
<Hyperlink Click="itemSelected" Tag="{Binding}">
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value}"/>
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value}"
Visibility="Collapsed" x:Name="txt2"/>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Cells[ 1].Value}" Value="False">
<Setter TargetName="txt1" Property="Visibility" Value="Collapsed"/>
<Setter TargetName="txt2" Property="Visibility" Value="Visible"/>
</DataTrigger>
</ControlTemplate.Triggers>
</Style>
I hope this helps.