Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 69 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,69 @@
# How-to-open-a-image-file-from-DataGridTemplateColumn
This demo shows how to open a image in a DataGridTemplateColumn
# How do you open a image file from DataGridTemplateColumn in .NET MAUI DataGrid?
In this article, we will show you how to open a image file from DataGridTemplateColumn in [.Net Maui DataGrid](https://www.syncfusion.com/maui-controls/maui-datagrid).

## xaml
```
<syncfusion:SfDataGrid x:Name="sfGrid"
SelectionMode="Single"
NavigationMode="Cell"
GridLinesVisibility="Both"
ColumnWidthMode="Auto"
HeaderGridLinesVisibility="Both"
AutoGenerateColumnsMode="None"
ItemsSource="{Binding Employees}">

<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridTextColumn MappingName="EmployeeID"
HeaderText="Employee ID" />
<syncfusion:DataGridTextColumn MappingName="Name"
HeaderText="Employee Name" />
<syncfusion:DataGridTextColumn MappingName="Designation"
HeaderText="Designation" />
<syncfusion:DataGridTemplateColumn HeaderText="Image">
<syncfusion:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ImageButton Source="dot_icon.png"
Clicked="ImageButton_Clicked" />
</DataTemplate>
</syncfusion:DataGridTemplateColumn.CellTemplate>
</syncfusion:DataGridTemplateColumn>
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
```

## C#
The below code illustrates how to open a image file from DataGridTemplateColumn in DataGrid.
```
private void ImageButton_Clicked(object sender, EventArgs e)
{
var imageButton = sender as ImageButton;
var rowData = (imageButton.BindingContext as Employee);

if (rowData != null)
{
// Assuming you have a method to show the image
ShowPartImage(rowData.URL);
}
}

private async Task ShowPartImage(string imageUrl)
{
// Implement your logic to display the image
// For example, you can open a new page or a popup with the image
await Navigation.PushAsync(new PartImage(imageUrl));
}
```
![OpenImg.gif](https://support.syncfusion.com/kb/agent/attachment/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjI3OTg3Iiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.EesChAO08inaEV5h7V57fgpJFlXIO9hZuC07jX0KIzQ)

[View sample in GitHub](https://github.com/SyncfusionExamples/How-to-open-a-image-file-from-DataGridTemplateColumn)

Take a moment to explore this [documentation](https://help.syncfusion.com/maui/datagrid/overview), where you can find more information about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this [link](https://www.syncfusion.com/maui-controls/maui-datagrid) to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid).

##### Conclusion

I hope you enjoyed learning about how to open a image file from DataGridTemplateColumn in .NET MAUI DataGrid (SfDataGrid).

You can refer to our [.NET MAUI DataGrid’s feature tour](https://www.syncfusion.com/maui-controls/maui-datagrid) page to learn about its other groundbreaking feature representations. You can also explore our [.NET MAUI DataGrid Documentation](https://help.syncfusion.com/maui/datagrid/getting-started) to understand how to present and manipulate data.
For current customers, you can check out our .NET MAUI components on the [License and Downloads](https://www.syncfusion.com/sales/teamlicense) page. If you are new to Syncfusion, you can try our 30-day [free trial](https://www.syncfusion.com/downloads/maui) to explore our .NET MAUI DataGrid and other .NET MAUI components.

If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our [support forums](https://www.syncfusion.com/forums), [Direct-Trac](https://support.syncfusion.com/create) or [feedback portal](https://www.syncfusion.com/feedback/maui?control=sfdatagrid), or the feedback portal. We are always happy to assist you!
14 changes: 14 additions & 0 deletions SfDataGridSample/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SfDataGridSample"
x:Class="SfDataGridSample.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
12 changes: 12 additions & 0 deletions SfDataGridSample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SfDataGridSample
{
public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new AppShell();
}
}
}
15 changes: 15 additions & 0 deletions SfDataGridSample/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="SfDataGridSample.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SfDataGridSample"
Shell.FlyoutBehavior="Disabled"
Title="SfDataGridSample">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
10 changes: 10 additions & 0 deletions SfDataGridSample/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SfDataGridSample
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
41 changes: 41 additions & 0 deletions SfDataGridSample/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"
xmlns:local="clr-namespace:SfDataGridSample"
x:Class="SfDataGridSample.MainPage">

<ContentPage.BindingContext>
<local:EmployeeViewModel x:Name="viewModel"/>
</ContentPage.BindingContext>


<syncfusion:SfDataGrid x:Name="sfGrid"
Margin="10"
SelectionMode="Single"
NavigationMode="Cell"
GridLinesVisibility="Both"
ColumnWidthMode="Auto"
HeaderGridLinesVisibility="Both"
AutoGenerateColumnsMode="None"
ItemsSource="{Binding Employees}">

<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridTextColumn MappingName="EmployeeID"
HeaderText="Employee ID" />
<syncfusion:DataGridTextColumn MappingName="Name"
HeaderText="Employee Name" />
<syncfusion:DataGridTextColumn MappingName="Designation"
HeaderText="Designation" />
<syncfusion:DataGridTemplateColumn HeaderText="Image">
<syncfusion:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ImageButton Source="dot_icon.png"
Clicked="ImageButton_Clicked" />
</DataTemplate>
</syncfusion:DataGridTemplateColumn.CellTemplate>
</syncfusion:DataGridTemplateColumn>
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

</ContentPage>
33 changes: 33 additions & 0 deletions SfDataGridSample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Syncfusion.Maui.DataGrid;
using System.Collections;
using System.Reflection;

namespace SfDataGridSample
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}

private void ImageButton_Clicked(object sender, EventArgs e)
{
var imageButton = sender as ImageButton;
var rowData = (imageButton.BindingContext as Employee);

if (rowData != null)
{
// Assuming you have a method to show the image
ShowPartImage(rowData.URL);
}
}

private async Task ShowPartImage(string imageUrl)
{
// Implement your logic to display the image
// For example, you can open a new page or a popup with the image
await Navigation.PushAsync(new PartImage(imageUrl));
}
}
}
27 changes: 27 additions & 0 deletions SfDataGridSample/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using Syncfusion.Maui.Core;
using Syncfusion.Maui.Core.Hosting;
namespace SfDataGridSample
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureSyncfusionCore()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
}
13 changes: 13 additions & 0 deletions SfDataGridSample/Model/Employee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel;

namespace SfDataGridSample
{
public class Employee
{
public int EmployeeID { get; set; }
public string Name { get; set; }
public string Designation { get; set; }
public string URL { get; set; }
public string MapUrl { get; set; }
}
}
10 changes: 10 additions & 0 deletions SfDataGridSample/PartImage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SfDataGridSample.PartImage"
Title="PartImage">
<StackLayout>
<Image x:Name="imageView" WidthRequest="1400" HeightRequest="500"
Aspect="AspectFit" />
</StackLayout>
</ContentPage>
10 changes: 10 additions & 0 deletions SfDataGridSample/PartImage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SfDataGridSample;

public partial class PartImage : ContentPage
{
public PartImage(string imageUrl)
{
InitializeComponent();
imageView.Source = imageUrl;
}
}
6 changes: 6 additions & 0 deletions SfDataGridSample/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
11 changes: 11 additions & 0 deletions SfDataGridSample/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace SfDataGridSample
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
}
16 changes: 16 additions & 0 deletions SfDataGridSample/Platforms/Android/MainApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Android.App;
using Android.Runtime;

namespace SfDataGridSample
{
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
10 changes: 10 additions & 0 deletions SfDataGridSample/Platforms/MacCatalyst/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Foundation;

namespace SfDataGridSample
{
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
14 changes: 14 additions & 0 deletions SfDataGridSample/Platforms/MacCatalyst/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- See https://aka.ms/maui-publish-app-store#add-entitlements for more information about adding entitlements.-->
<dict>
<!-- App Sandbox must be enabled to distribute a MacCatalyst app through the Mac App Store. -->
<key>com.apple.security.app-sandbox</key>
<true/>
<!-- When App Sandbox is enabled, this value is required to open outgoing network connections. -->
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

38 changes: 38 additions & 0 deletions SfDataGridSample/Platforms/MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- The Mac App Store requires you specify if the app uses encryption. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/itsappusesnonexemptencryption -->
<!-- <key>ITSAppUsesNonExemptEncryption</key> -->
<!-- Please indicate <true/> or <false/> here. -->

<!-- Specify the category for your app here. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/lsapplicationcategorytype -->
<!-- <key>LSApplicationCategoryType</key> -->
<!-- <string>public.app-category.YOUR-CATEGORY-HERE</string> -->
<key>UIDeviceFamily</key>
<array>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>
16 changes: 16 additions & 0 deletions SfDataGridSample/Platforms/MacCatalyst/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ObjCRuntime;
using UIKit;

namespace SfDataGridSample
{
public class Program
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
}
Loading