You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blazor/common/migration/wpf-blazor-migration.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -163,7 +163,7 @@ Data binding is a fundamental concept in both WPF and Blazor, but the implementa
163
163
164
164
In WPF, the `DataContext` property is a powerful mechanism that enables declarative data binding. You set the `DataContext` to a view model instance that typically implements `INotifyPropertyChanged`, and XAML bindings automatically resolve against this object. This allows UI elements to automatically update when the underlying data changes.
165
165
166
-
When the data source implements `INotifyCollectionChanged` (such as `ObservableCollection<T>`), the `SfDataGrid` control automatically refreshes the UI when items are added, removed, or when the list is cleared. However, when using a standard `List<T>`, the grid will not automatically refresh when the collection is modified.
166
+
When the data source implements [INotifyCollectionChanged](https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.inotifycollectionchanged?view=net-10.0) (such as [ObservableCollection<T>](https://learn.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.observablecollection-1?view=net-10.0)), the [SfDataGrid](https://www.syncfusion.com/wpf-controls/datagrid) control automatically refreshes the UI when items are added, removed, or when the list is cleared. However, when using a standard `List<T>`, the grid will not automatically refresh when the collection is modified.
167
167
168
168
{% tabs %}
169
169
{% highlight c# tabtitle="MainWindow.xaml.cs" %}
@@ -230,7 +230,7 @@ public class Order
230
230
231
231
In Blazor, data flows through component parameters and the `@bind` directive. Instead of a global `DataContext`, each component explicitly defines its data dependencies through parameters. This approach provides more explicit data flow, better component composition, and type-safe binding.
232
232
233
-
The [Blazor DataGrid](https://www.syncfusion.com/blazor-components/blazor-datagrid) supports binding to any `IEnumerable` collection such as `List<T>`, `ObservableCollection<T>`, collections of `ExpandoObject`, `DynamicObject`, or `DataTable`, directly to the [DataSource](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_DataSource) property of the Grid. When using `ObservableCollection<T>`, the component automatically reflects changes made externally. For standard `List<T>`, call the [Refresh](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_Refresh_System_Boolean_) method to reflect externally made changes to avoid tracking changes for performance considerations.
233
+
The [Blazor DataGrid](https://www.syncfusion.com/blazor-components/blazor-datagrid) supports binding to any `IEnumerable` collection such as `List<T>`, [ObservableCollection<T>](https://learn.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.observablecollection-1?view=net-10.0), collections of [ExpandoObject](https://learn.microsoft.com/en-us/dotnet/api/system.dynamic.expandoobject?view=net-10.0), [DynamicObject](https://learn.microsoft.com/en-us/dotnet/api/system.dynamic.dynamicobject?view=net-10.0), or `DataTable`, directly to the [DataSource](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_DataSource) property of the Grid. When using `ObservableCollection<T>`, the component automatically reflects changes made externally. For standard `List<T>`, call the [Refresh](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_Refresh_System_Boolean_) method to reflect externally made changes to avoid tracking changes for performance considerations.
234
234
235
235
{% tabs %}
236
236
{% highlight razor tabtitle="Orders.razor" %}
@@ -272,14 +272,14 @@ The [Blazor DataGrid](https://www.syncfusion.com/blazor-components/blazor-datagr
272
272
{% endhighlight %}
273
273
{% endtabs %}
274
274
275
-
**Key differences in data binding:**
275
+
**Key differences in data binding**
276
276
277
277
| Aspect | WPF DataContext | Blazor Parameters |
278
278
|---|---|---|
279
279
| Scope | Global to window/control hierarchy | Explicit per component |
280
280
| Binding declaration |`{Binding PropertyName}` in XAML |`@PropertyName` or `@bind` in Razor |
| Collection type |`ObservableCollection<T>` for automatic notifications |`List<T>` or `ObservableCollection<T>` (for `ObservableCollection<T>`, automatic notifications; for `List<T>`, call `Refresh()` method) |
282
+
| Collection type |`ObservableCollection<T>` for automatic notifications |`List<T>` or `ObservableCollection<T>` (for `ObservableCollection<T>`, automatic notifications; for `List<T>`, call [Refresh()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_Refresh_System_Boolean_) method) |
283
283
| Type safety | Resolved at runtime | Type-safe at compile time |
| Update notification | Automatic via `PropertyChanged` event | Automatic for `ObservableCollection<T>` or manual via `Refresh()` or re-assignment for `List<T>`|
@@ -462,7 +462,7 @@ Blazor components render as standard HTML and CSS in the browser, requiring a sh
462
462
{% endhighlight %}
463
463
{% endtabs %}
464
464
465
-
**Key differences:**
465
+
**Key differences**
466
466
467
467
| Aspect | WPF | Blazor |
468
468
|---|---|---|
@@ -473,7 +473,7 @@ Blazor components render as standard HTML and CSS in the browser, requiring a sh
* Replace fixed pixel dimensions with flexible CSS units (percentages, em, rem) where appropriate
479
479
* Use CSS Flexbox or CSS Grid in place of WPF layout panels (StackPanel, Grid, DockPanel)
@@ -485,7 +485,7 @@ Blazor components render as standard HTML and CSS in the browser, requiring a sh
485
485
486
486
**WPF lifecycle**
487
487
488
-
WPF controls follow a predictable, synchronous lifecycle: `Loaded`, property change notifications via `DependencyProperty`, `DataContextChanged`, and `Unloaded`. Event handling is direct through routed events and delegates, executing synchronously on the UI thread. This ensures tight control over component state but can block the UI if long-running operations aren't handled properly.
488
+
WPF controls usually follow a synchronous lifecycle. Events like `Loaded`and `Unloaded` are used to start work, clean up resources, and respond to user actions directly on the UI thread. This approach is straightforward, but long-running tasks can block the interface if they are not handled carefully.
489
489
490
490
{% tabs %}
491
491
{% highlight c# tabtitle="MainWindow.xaml.cs" %}
@@ -523,7 +523,7 @@ public class MainWindow : Window
523
523
524
524
**Blazor lifecycle**
525
525
526
-
Blazor components use an asynchronous lifecycle model designed for server-client communication: `OnInitialized` / `OnInitializedAsync`, `OnParametersSet` / `OnParametersSetAsync`, and `OnAfterRender` / `OnAfterRenderAsync`. Event handling is through `EventCallback` delegates, supporting both synchronous and asynchronous operations. This asynchronous model prevents blocking the server-side interactive connection but requires a shift in thinking about component initialization and updates.
526
+
Blazor uses an asynchronous lifecycle that fits browser rendering and server communication. Common lifecycle methods include `OnInitializedAsync`, `OnParametersSetAsync`, and `OnAfterRenderAsync`. Event handling is also flexible, so component logic can run synchronously or asynchronously depending on the task.
527
527
528
528
{% tabs %}
529
529
{% highlight razor tabtitle="Sample.razor" %}
@@ -612,26 +612,26 @@ Blazor components use an asynchronous lifecycle model designed for server-client
0 commit comments