Breaking Change T1001744
Visible to All Users

TreeView, ContextMenu - Some API members related to data binding are now obsolete. A new data binding approach was introduced

What Changed

We marked the TreeView's and Context Menu's *Expression properties as obsolete:

TreeView properties

Context Menu properties

Reasons for Change

In v21.1, we introduced a new way to bind the TreeView and Context Menu to data. You can now use the DataMappings property to bind these components to flat and hierarchical data. This approach has the following advantages:

  • You do not need to use explicit type conversion (casting) that was required in *Expression properties.
  • Properties related to binding are now specified in a separate tag <DataMappings>.
  • The TreeView and Context Menu components can use collections that implement the INotifyCollectionChanged interface as a data source.

Impact on Existing Apps

These changes affect applications if the properties listed above are specified.

Razor
<DxTreeView Data="@ChemicalElements.Groups" TextExpression="@(dataItem => ((ChemicalElementGroup)dataItem).Name)" ChildrenExpression="@(dataItem => ((ChemicalElementGroup)dataItem).Groups)"> </DxTreeView>
Razor
<DxContextMenu Data="@MenuItems" ItemClick="((args) => { InvokeAsync(StateHasChanged); })" TextExpression="(item => (item as TextFormattingMenuItem).Text)" ClickExpression="(item => (item as TextFormattingMenuItem).Click)" ChildrenExpression="(item => (item as TextFormattingMenuItem).Children)" BeginGroupExpression="(item => (item as TextFormattingMenuItem).BeginGroup)" IconUrlExpression="(item => (item as TextFormattingMenuItem).IconUrl)" @ref="@ContextMenu"> </DxContextMenu>

How to Update Existing Apps

Follow the steps below to update your applications:

  • Make sure the Data property specifies a data source.
  • Remove the obsolete properties.
  • Add the <DataMappings> tag to the component markup.
  • Create the DxTreeViewDataMapping or DxContextMenuDataMapping instance and map its properties to data source fields. Mappings are used to link the component's data model to the data source.
    For flat data, the Key and ParentKey properties are required.
    For hierarchical data, the Children property is required.

You can also create several DxTreeViewDataMapping or DxContextMenuDataMapping instances to specify different mappings for different item hierarchy levels. Use the Level property to specify the item hierarchy level for which data mappings are applied.

If you used the DxContextMenu.ClickExpression property, replace it with the ItemClick event handler.

Razor
<DxTreeView Data="@ChemicalElements.Groups"> <DataMappings> <DxTreeViewDataMapping Children="Groups" Text="Name"/> </DataMappings> </DxTreeView>
Razor
<DxContextMenu Data="@MenuItems" ItemClick="@ItemClick"> <DataMappings> <DxContextMenuDataMapping Children="Children" Text="Text" IconUrl="IconUrl" BeginGroup="BeginGroup" /> </DataMappings> </DxContextMenu> @code { // .... void ItemClick(ContextMenuItemClickEventArgs args) { ((TextFormattingMenuItem)args.ItemInfo.DataItem).Click(); InvokeAsync(StateHasChanged); } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.