Skip to content

Commit 46a0465

Browse files
author
shobika.palani
committed
how to create custom column from existing column in wpf and uwp datagrid
1 parent e5c62de commit 46a0465

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+17873
-0
lines changed

UWP/App.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application
2+
x:Class="SfDataGridDemo.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:SfDataGridDemo"
6+
RequestedTheme="Light">
7+
8+
</Application>

UWP/App.xaml.cs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Windows.ApplicationModel;
7+
using Windows.ApplicationModel.Activation;
8+
using Windows.Foundation;
9+
using Windows.Foundation.Collections;
10+
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Controls;
12+
using Windows.UI.Xaml.Controls.Primitives;
13+
using Windows.UI.Xaml.Data;
14+
using Windows.UI.Xaml.Input;
15+
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Navigation;
17+
18+
namespace SfDataGridDemo
19+
{
20+
/// <summary>
21+
/// Provides application-specific behavior to supplement the default Application class.
22+
/// </summary>
23+
sealed partial class App : Application
24+
{
25+
/// <summary>
26+
/// Initializes the singleton application object. This is the first line of authored code
27+
/// executed, and as such is the logical equivalent of main() or WinMain().
28+
/// </summary>
29+
public App()
30+
{
31+
this.InitializeComponent();
32+
this.Suspending += OnSuspending;
33+
}
34+
35+
/// <summary>
36+
/// Invoked when the application is launched normally by the end user. Other entry points
37+
/// will be used such as when the application is launched to open a specific file.
38+
/// </summary>
39+
/// <param name="e">Details about the launch request and process.</param>
40+
protected override void OnLaunched(LaunchActivatedEventArgs e)
41+
{
42+
#if DEBUG
43+
if (System.Diagnostics.Debugger.IsAttached)
44+
{
45+
this.DebugSettings.EnableFrameRateCounter = true;
46+
}
47+
#endif
48+
Frame rootFrame = Window.Current.Content as Frame;
49+
50+
// Do not repeat app initialization when the Window already has content,
51+
// just ensure that the window is active
52+
if (rootFrame == null)
53+
{
54+
// Create a Frame to act as the navigation context and navigate to the first page
55+
rootFrame = new Frame();
56+
57+
rootFrame.NavigationFailed += OnNavigationFailed;
58+
59+
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
60+
{
61+
//TODO: Load state from previously suspended application
62+
}
63+
64+
// Place the frame in the current Window
65+
Window.Current.Content = rootFrame;
66+
}
67+
68+
if (e.PrelaunchActivated == false)
69+
{
70+
if (rootFrame.Content == null)
71+
{
72+
// When the navigation stack isn't restored navigate to the first page,
73+
// configuring the new page by passing required information as a navigation
74+
// parameter
75+
rootFrame.Navigate(typeof(MainPage), e.Arguments);
76+
}
77+
// Ensure the current window is active
78+
Window.Current.Activate();
79+
}
80+
}
81+
82+
/// <summary>
83+
/// Invoked when Navigation to a certain page fails
84+
/// </summary>
85+
/// <param name="sender">The Frame which failed navigation</param>
86+
/// <param name="e">Details about the navigation failure</param>
87+
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
88+
{
89+
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
90+
}
91+
92+
/// <summary>
93+
/// Invoked when application execution is being suspended. Application state is saved
94+
/// without knowing whether the application will be terminated or resumed with the contents
95+
/// of memory still intact.
96+
/// </summary>
97+
/// <param name="sender">The source of the suspend request.</param>
98+
/// <param name="e">Details about the suspend request.</param>
99+
private void OnSuspending(object sender, SuspendingEventArgs e)
100+
{
101+
var deferral = e.SuspendingOperation.GetDeferral();
102+
//TODO: Save application state and stop any background activity
103+
deferral.Complete();
104+
}
105+
}
106+
}
1.4 KB
Loading
7.52 KB
Loading
2.87 KB
Loading
1.61 KB
Loading
1.23 KB
Loading

UWP/Assets/StoreLogo.png

1.42 KB
Loading
3.13 KB
Loading
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using Syncfusion.UI.Xaml.Grid;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Windows.UI.Xaml.Data;
9+
10+
namespace SfDataGridDemo
11+
{
12+
public class DateTimeOffsetFormatConverter : IValueConverter
13+
{
14+
15+
private GridDateTimeOffsetColumn cachedColumn;
16+
17+
public DateTimeOffsetFormatConverter(GridDateTimeOffsetColumn column)
18+
{
19+
cachedColumn = column;
20+
}
21+
22+
object IValueConverter.Convert(object value, Type targetType, object parameter, string language)
23+
{
24+
value = ((DateTimeOffset)value).DateTime;
25+
var column = cachedColumn as GridDateTimeOffsetColumn;
26+
27+
if (value == null || DBNull.Value == value)
28+
{
29+
if (column.AllowNullValue && column.MaxDate != System.DateTime.MaxValue && column.WaterMark.ToString() == string.Empty)
30+
return column.MaxDate;
31+
32+
if (column.AllowNullValue && column.WaterMark.ToString() != string.Empty)
33+
return column.WaterMark;
34+
35+
if (column.MaxDate != System.DateTime.MaxValue)
36+
return column.MaxDate;
37+
}
38+
DateTime _columnValue;
39+
40+
_columnValue = (DateTime)value;
41+
42+
if (_columnValue < column.MinDate)
43+
_columnValue = column.MinDate;
44+
45+
if (_columnValue > column.MaxDate)
46+
_columnValue = column.MaxDate;
47+
48+
return _columnValue.ToString(column.FormatString, CultureInfo.CurrentUICulture);
49+
}
50+
51+
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, string language)
52+
{
53+
throw new NotImplementedException();
54+
}
55+
}
56+
57+
public class DateTimeOffsetToDateTimeConverter : IValueConverter
58+
{
59+
object IValueConverter.Convert(object value, Type targetType, object parameter, string language)
60+
{
61+
if (value == null)
62+
return null;
63+
return ((DateTimeOffset)value).DateTime;
64+
}
65+
66+
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, string language)
67+
{
68+
69+
if (value == null)
70+
return null;
71+
return value is DateTimeOffset ? value : new DateTimeOffset((DateTime)value);
72+
73+
}
74+
}
75+
public class GridDateTimeOffsetColumn : GridDateTimeColumn
76+
{
77+
protected override void SetDisplayBindingConverter()
78+
{
79+
80+
if ((DisplayBinding as Binding).Converter == null)
81+
(DisplayBinding as Binding).Converter = new DateTimeOffsetFormatConverter(this);
82+
83+
if ((ValueBinding as Binding).Converter == null)
84+
(ValueBinding as Binding).Converter = new DateTimeOffsetToDateTimeConverter();
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)