Hi Team,i have a small issue that i need to create the XamGrid column from code behind and catch the Hyperlink Click event._grid.Columns.Add(new HyperlinkColumn { Key = columnKey, HeaderText = FormatColumnHeader(entry.Key), //FormatString = formatString, HorizontalContentAlignment = rightAlign ? HorizontalAlignment.Right : HorizontalAlignment.Left, Width = new ColumnWidth( firstColumn ? ResultGridView.MeasureStringWidth("00000000") : columnWidth, false), MinimumWidth = 30, CellStyle = Application.Current.Resources["CellStyle"] as Style, HeaderTemplate = Application.Current.Resources["HeaderTemplate"] as DataTemplate, IsMovable = !firstColumn, IsHideable = !firstColumn, IsResizable = true, IsSortable = true, });this is my codeand the cell Style is <Style x:Key="CellStyle" TargetType="ig:CellControl"> <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}" /> <Setter Property="FontSize" Value="{StaticResource SmallFontSize}" /> <Setter Property="FontFamily" Value="{StaticResource ContentFontFamily}" /> <Setter Property="MinHeight" Value="30" /> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="Background" Value="{StaticResource CellItemNormalBackgroundBrush}" /> <Setter Property="BorderBrush" Value="{StaticResource CellItemNormalBorderBrush}" /> <Setter Property="BorderThickness" Value="0,0,1.5,1" /> <Setter Property="Padding" Value="6,4" /> <Setter Property="ResizingThreshold" Value="20" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ig:CellControl"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal" /> <VisualState x:Name="MouseOver"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="hoverElem" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="00:00:00"> <DiscreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Alternate"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="altElem" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="00:00:00"> <DiscreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="SelectedStates"> <VisualState x:Name="NotSelected" /> <VisualState x:Name="Selected"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="rowSelected" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="00:00:00"> <DiscreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ActiveSelected" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="00:00:00"> <DiscreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="ActiveStates"> <VisualState x:Name="InActive" /> <VisualState x:Name="Active" /> </VisualStateGroup> <VisualStateGroup x:Name="EditingStates"> <VisualState x:Name="NotEditing" /> <VisualState x:Name="Editing" /> </VisualStateGroup> <VisualStateGroup x:Name="FixedStates"> <VisualState x:Name="UnFixed" /> <VisualState x:Name="Fixed" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border x:Name="Root" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" /> <Border x:Name="altElem" Background="{StaticResource CellItemAltNormalBackgroundBrush}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Visibility="Collapsed" /> <Border x:Name="hoverElem" Margin="{TemplateBinding BorderThickness}" Background="{StaticResource CellItemHoverBackgroundBrush}" BorderThickness="0" Visibility="Collapsed" /> <Border x:Name="rowSelected" Margin="{TemplateBinding BorderThickness}" Background="{StaticResource CellItemSelectedBorderBrush}" BorderThickness="0" Opacity="0.25" Visibility="Collapsed" /> <Border x:Name="ActiveSelected" BorderBrush="{StaticResource CellItemSelectedBorderBrush}" BorderThickness="2" Visibility="Collapsed" /> <ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>Please Help me out
Hi Micheal,I understand that CellClicked will only be raised when cell element is clicked. But it is being raised multiple times when i even click the empty area in the cell. and there are a couple of issues as well.1. as you said I should Check the type Cell and i did. but the sender is always XamGrid.
2. the hyperlink click event is fired anyway and even before we reach to CellClicked.
3. Please understand I need to hook the Hyperlink Click event. so I can manipulate the values as required. I would be grateful if you would please provide an example. below is the code of how i am adding a column. _grid.Columns.Add(new HyperlinkColumn { Key = columnKey, HeaderText = FormatColumnHeader(entry.Key), //FormatString = formatString, HorizontalContentAlignment = rightAlign ? HorizontalAlignment.Right : HorizontalAlignment.Left, Width = new ColumnWidth( firstColumn ? ResultGridView.MeasureStringWidth("00000000") : columnWidth, false), MinimumWidth = 30, CellStyle = Application.Current.Resources["CellStyle"] as Style, HeaderTemplate = Application.Current.Resources["HeaderTemplate"] as DataTemplate, IsMovable = !firstColumn, IsHideable = !firstColumn, IsResizable = true, IsSortable = true, TargetName = "_new", }); _grid.CellClicked += _grid_CellClicked;
void _grid_CellClicked(object sender, CellClickedEventArgs e) { if (sender is Cell) {
} }Regards
Ammad Javaid
Hello Ammad,
Thank you for following up. The CellClicked event should only be raised when a Cell element is clicked.
The Cell object is exposed as an event argument for the CellClicked event. Whereby you can track down the Cell.Column associated.
In the event you can place an "if check" to determine if the sender of the event is indeed a type Cell, but and check it's Column property.
Let me know if you have any questions.
Hi Micheal, Thank you for your reply. There are multiple columns in the Grid, and we dont have any specific column for Hyperlink. It varies depending on the Name of the Column. If i use CellClicked event, It will fire every single time we click on the cell, even if its not on the hyperlink itself. is there a way that i can know in the CellClicked event that the click was done on the hyperlink specifically and not on the empty space around the text? Regards,Ammad
Thank you for contacting Infragistics.
1. What specific requirements do you have when clicking the hyperlink other than navigation?
The HyperlinkColumn doesn't expose a click event directly. You may utilize the XamGrid's CellClicked event, which fires when the user left clicks on a cell.
2. You set the HyperLinkColumn's TargetName property to "_new" or "_blank" to navigate the address in a new page or tab. "_self" should be the same page.
<ig:HyperlinkColumn TargetName="_blank">
1 More thing. When hyperlink is clicked it opens the URL in the same window. rather than in a separate window.