WPF interface development: how to establish a binding path in the WPF Grid control unit

DevExpress Technical Exchange Group 2: 775869749 Welcome to join the group discussion

Download DevExpress v20.1 full version

With DevExpress WPF Controls , you can create XAML-based applications with powerful interactive functions that focus on the needs of contemporary customers and build a new generation of touch-enabled solutions in the future.

System background

  • Platform: WPF
  • Product: DXGrid for WPF

The DataContext of the cell element contains the EditGridCellData  object.

Use the following binding path to access cell values, columns, and ViewModel properties:

  • Value-access the current cell value;
  • Column-access the current column;
  • RowData.Row.[YourPropertyName]-Access the properties of the object from the ItemsSource collection;
  • Data.[FieldName]-Access column values ​​and unbound column values ​​in Server Mode;
  • View.DataContext.[YourPropertyName]-Access the ViewModel properties of the grid.

The binding used in this article works as follows:

  • Bind ComboBoxEdit.ItemsSource to the Countrys property of the grid's ViewModel:
<dxe:ComboBoxEdit x:Name="PART_Editor" DisplayMember="Name" ItemsSource="{Binding View.DataContext.Countries}" />

Important note: If you want to assign the same ItemsSource collection to all editors in the column, use the EditSettings property instead of CellTemplate to get better performance.

  • Bind ComboBoxEdit.ItemsSource to the Cities property stored at the item level:
<dxe:ComboBoxEdit x:Name="PART_Editor" ItemsSource="{Binding RowData.Row.Country.Cities}" />
  • Bind Button.Visibility to the unbound column value, and the FieldName of the unbound column is "Visited":
<Button Visibility="{Binding Data.Visited, Converter={dx:BooleanToVisibilityConverter}}">Hide</Button>
  • Bind tooltips to display the FieldName of the current column and a cell value:
<Setter Property="ToolTip"> 
<Setter.Value> 
<MultiBinding Converter="{local:CellTooltipConverter}"> 
<Binding Path="Column.FieldName" /> 
<Binding Path="Value" /> 
</MultiBinding> 
</Setter.Value> 
</Setter>

Important note: You can use the CellToolTipBinding property to specify tool tips for grid cells.

  • Bind the background of the cell to the Color property stored at the item level:
<!-- xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"; --> 
<Style.Triggers> 
<Trigger Property="SelectionState" Value="None"> 
<Setter Property="Background" Value="{Binding RowData.Row.Color, Converter={dxmvvm:ColorToBrushConverter}}" /> 
</Trigger> 
</Style.Triggers>

 

Huidu high-end UI interface development

Guess you like

Origin blog.csdn.net/AABBbaby/article/details/108461808