<Style TargetType="HyperlinkButton">
<Setter Property="Foreground" Value="Green" />
</Style> |
<interact:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="CurrentCellRequestNavigate">
<core:InvokeCommandAction Command="{Binding CurrentCellRequestNavigateCommand}" />
</core:EventTriggerBehavior>
</interact:Interaction.Behaviors>
public void Navigate(object args)
{
string str = "http://www.Syncfusion.com";
Launcher.LaunchUriAsync(new Uri(str));
} |
<!-- DataGrid --> <grid:SfDataGrid x:Name="sfDataGrid" Grid.Row="1" Padding="0,10,0,0" ItemsSource="{Binding Forms}" SelectedItem="{Binding SelectedForm, Mode=TwoWay}" AutoGenerateColumns="False" ColumnSizer="Star" NavigationMode="Row" HeaderRowHeight="50"> <grid:SfDataGrid.Columns> <!-- Form Number --> <grid:GridHyperlinkColumn MappingName="form_code" helpers:SfDgColumnSizerAttachedProperty.ColumnSizer="2"> <grid:GridHyperlinkColumn.HeaderTemplate> <DataTemplate> <TextBlock x:Uid="HomeSfColumnFormCodeTextBlock" TextAlignment="Center" TextWrapping="Wrap" /> </DataTemplate> </grid:GridHyperlinkColumn.HeaderTemplate> </grid:GridHyperlinkColumn> <!-- Submitter --> <grid:GridTextColumn x:Uid="HomeSfColumnSubmitter" MappingName="submitterName" helpers:SfDgColumnSizerAttachedProperty.ColumnSizer="3"/> <!-- Company --> <grid:GridTextColumn x:Uid="HomeSfColumnCompany" MappingName="company" /> <!-- Submission date --> <grid:GridTextColumn DisplayBinding="{Binding validation_date, Converter={StaticResource DateFormatConverter}}" helpers:SfDgColumnSizerAttachedProperty.ColumnSizer="2"> <grid:GridTextColumn.HeaderTemplate> <DataTemplate> <TextBlock x:Uid="HomeSfColumnSubmissionDateTextBlock" TextAlignment="Center" TextWrapping="Wrap" /> </DataTemplate> </grid:GridTextColumn.HeaderTemplate> </grid:GridTextColumn> <!-- Status --> <grid:GridTextColumn x:Uid="HomeSfColumnStatus" MappingName="statusLabel" helpers:SfDgColumnSizerAttachedProperty.ColumnSizer="2"/> <!-- ... more columns --> </grid:SfDataGrid.Columns> </grid:SfDataGrid> |
<grid:SfDataGrid.Resources> <Style TargetType="HyperlinkButton"> <Setter Property="Foreground" Value="Red" /> </Style> </grid:SfDataGrid.Resources> |
async void OnSfDataGridCurrentCellRequestNavigate(object sender, CurrentCellRequestNavigateEventArgs args) { var form = args.RowData as Forms; var viewModel = this.DataContext as HomeViewModel; viewModel.ClickedForm = form; viewModel.OpenForm(); } |
<Style TargetType="TextBlock"> <Setter Property="Foreground" Value="{StaticResource FontColor}" /> </Style> <Style x:Key="AppTitleTextBlockStyle" TargetType="TextBlock" BasedOn="{StaticResource BaseTextBlockStyle}"> <Setter Property="Margin" Value="12,6,0,6" /> <Setter Property="VerticalAlignment" Value="Center" /> </Style> <Style x:Key="ParagraphTextBlockStyle" TargetType="TextBlock" BasedOn="{StaticResource BodyTextBlockStyle}"> <Setter Property="Margin" Value="0,1,0,34" /> <Setter Property="TextWrapping" Value="Wrap" /> <Setter Property="TextTrimming" Value="CharacterEllipsis" /> </Style> <Style x:Key="TitleTextBlockStyle" TargetType="TextBlock" BasedOn="{StaticResource TitleTextBlockStyle}"> <Setter Property="Margin" Value="0,1,0,18" /> </Style> ... |
this.sfGrid.CellRenderers.Remove("Hyperlink");
this.sfGrid.CellRenderers.Add("Hyperlink", new CustomCellRendererExt());
public class CustomCellRendererExt : GridCellHyperlinkRenderer
{
public override void OnInitializeEditElement(DataColumnBase dataColumn, HyperlinkButton uiElement, object dataContext)
{
base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
var column = dataColumn.GridColumn;
uiElement.SetValue(FrameworkElement.MarginProperty, column.Padding);
uiElement.SetValue(Control.PaddingProperty, column.Padding);
uiElement.SetValue(Control.VerticalAlignmentProperty, column.VerticalAlignment);
var hyperLinkColumn = (GridHyperlinkColumn)column;
var textBlock = new TextBlock();
uiElement.Content = textBlock;
textBlock.SetBinding(TextBlock.TextProperty, column.ValueBinding);
if (hyperLinkColumn == null)
return;
textBlock.Style = null;
textBlock.SetValue(TextBlock.TextWrappingProperty, hyperLinkColumn.TextWrapping);
uiElement.SetValue(TextBlock.TextWrappingProperty, hyperLinkColumn.TextWrapping);
uiElement.SetValue(Control.HorizontalAlignmentProperty, hyperLinkColumn.HorizontalAlignment);
}
} |
public class CustomCellRendererExt : GridCellHyperlinkRenderer
{
public override bool CanUpdateBinding(GridColumn column)
{
return true;
}
public override void OnUpdateEditBinding(DataColumnBase dataColumn, HyperlinkButton element, object dataContext)
{
var textblock = element.Content as TextBlock;
if (textblock == null || textblock.Inlines.Count == 0)
return;
var underline = textblock.Inlines[0] as Underline;
var run = underline.Inlines[0] as Run;
var displayval = this.DataGrid.View.GetPropertyAccessProvider().GetFormattedValue(dataContext, dataColumn.GridColumn.MappingName);
run.Text = displayval == null ? string.Empty : displayval.ToString();
base.OnUpdateEditBinding(dataColumn, element, dataContext);
}
public override void OnInitializeEditElement(DataColumnBase dataColumn, HyperlinkButton uiElement, object dataContext)
{
base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
var column = dataColumn.GridColumn;
uiElement.SetValue(FrameworkElement.MarginProperty, column.Padding);
uiElement.SetValue(Control.PaddingProperty, column.Padding);
uiElement.SetValue(Control.VerticalAlignmentProperty, column.VerticalAlignment);
var hyperLinkColumn = (GridHyperlinkColumn)column;
var textBlock = new TextBlock();
uiElement.Content = textBlock;
//textBlock.SetBinding(TextBlock.TextProperty, column.ValueBinding);
if (hyperLinkColumn == null)
return;
var underline = new Underline();
var run = new Run();
var displayval = this.DataGrid.View.GetPropertyAccessProvider().GetFormattedValue(dataContext, dataColumn.GridColumn.MappingName);
run.Text = displayval == null ? string.Empty : displayval.ToString();
underline.Inlines.Add(run);
textBlock.Inlines.Add(underline);
textBlock.Style = null;
textBlock.SetValue(TextBlock.TextWrappingProperty, hyperLinkColumn.TextWrapping);
uiElement.SetValue(TextBlock.TextWrappingProperty, hyperLinkColumn.TextWrapping);
uiElement.SetValue(Control.HorizontalAlignmentProperty, hyperLinkColumn.HorizontalAlignment);
}
} |
protected async override void SetFocus(FrameworkElement uiElement, bool needToFocus)
{
base.SetFocus(uiElement, needToFocus);
var hyperlinkControl = (HyperlinkButton)uiElement;
GridCell gridcell = null;
if (hyperlinkControl.Parent is GridCell)
gridcell = hyperlinkControl.Parent as GridCell;
var navigateText = string.Empty;
var rowColumnIndex = RowColumnIndex.Empty;
rowColumnIndex.RowIndex = gridcell != null ? gridcell.ColumnBase.RowIndex : new RowColumnIndex().RowIndex;
rowColumnIndex.ColumnIndex = gridcell != null ? gridcell.ColumnBase.ColumnIndex : new RowColumnIndex().ColumnIndex;
if (rowColumnIndex != null && !rowColumnIndex.IsEmpty)
{
//Get the column from rowColumnIndex.
var column = this.DataGrid.Columns[this.DataGrid.ResolveToGridVisibleColumnIndex(rowColumnIndex.ColumnIndex)];
var recordIndex = this.DataGrid.ResolveToRecordIndex(rowColumnIndex.RowIndex);
if (recordIndex < 0)
return;
var record1 = this.DataGrid.View.Records.GetItemAt(recordIndex);
navigateText = record1.GetType().GetProperty(column.MappingName).GetValue(record1).ToString();
}
const string pattern = @"((http|https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
if (navigateText != null)
{
var NavigateUri = Regex.IsMatch("http://www.Syncfusion.com", pattern)
? new Uri("http://www.Syncfusion.com")
: null;
if (NavigateUri == null)
return;
hyperlinkControl.NavigateUri = NavigateUri;
await Launcher.LaunchUriAsync(new Uri(hyperlinkControl.NavigateUri.AbsoluteUri));
}
} |
protected async override void SetFocus(FrameworkElement uiElement, bool needToFocus)
{
base.SetFocus(uiElement, needToFocus);
var hyperlinkControl = (HyperlinkButton)uiElement;
hyperlinkControl.FontStretch = Windows.UI.Text.FontStretch.UltraExpanded;
GridCell gridcell = null;
if (hyperlinkControl.Parent is GridCell)
gridcell = hyperlinkControl.Parent as GridCell;
var navigateText = string.Empty;
var rowColumnIndex = RowColumnIndex.Empty;
rowColumnIndex.RowIndex = gridcell != null ? gridcell.ColumnBase.RowIndex : new RowColumnIndex().RowIndex;
rowColumnIndex.ColumnIndex = gridcell != null ? gridcell.ColumnBase.ColumnIndex : new RowColumnIndex().ColumnIndex;
if (rowColumnIndex != null && !rowColumnIndex.IsEmpty)
{
//Get the column from rowColumnIndex.
var column = this.DataGrid.Columns[this.DataGrid.ResolveToGridVisibleColumnIndex(rowColumnIndex.ColumnIndex)];
var recordIndex = this.DataGrid.ResolveToRecordIndex(rowColumnIndex.RowIndex);
if (recordIndex < 0)
return;
var record1 = this.DataGrid.View.Records.GetItemAt(recordIndex);
navigateText = record1.GetType().GetProperty(column.MappingName).GetValue(record1).ToString();
}
MethodInfo dynMethod = this.DataGrid.GetType().GetMethod("CurrentCellRequestNavigateEvent",
BindingFlags.NonPublic | BindingFlags.Instance);
CurrentCellRequestNavigateEventArgs ob = new CurrentCellRequestNavigateEventArgs(DataGrid);
ob.GetType().GetProperty("NavigateText").SetValue(ob, navigateText);
ob.GetType().GetProperty("RowData").SetValue(ob, hyperlinkControl.DataContext);
ob.GetType().GetProperty("RowColumnIndex").SetValue(ob, rowColumnIndex);
dynMethod.Invoke(DataGrid, new object[] { ob });
} |
private bool isNavigate = false;
public void Navigate(object args)
{
if (!isNavigate)
{
string str = "http://www.Syncfusion.com";
Launcher.LaunchUriAsync(new Uri(str));
isNavigate = true;
}
} |
<syncfusion:SfDataGrid x:Name="sfGrid"
Grid.Row="1"
SelectionMode="Extended"
AddNewRowPosition="Top"
AllowEditing="True"
AllowFiltering="True"
CurrentCellBorderThickness="0"
AutoGenerateColumns="False"
GridValidationMode="InView"
ItemsSource="{Binding UserDetails}"
ShowRowHeader="True"/> |