Search code examples
data-bindinguwpdatagriduwp-xamlwindows-community-toolkit

DataGridBoundColumn does not contain a definition for BindingProperty


I am developing a UWP app. I have an xaml:

<Page
x:Class="SnapBilling.SyncModule.SyncView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" 
xmlns:local="using:SnapBilling.SyncModule.Converters"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">


<Grid>
    <controls:DataGrid x:Name="BackupSummaryDataGrid" 
                       AutoGenerateColumns="False"  
                       x:DefaultBindMode="TwoWay" 
                       Grid.Row="1" 
                       ItemsSource="{x:Bind Vm.PendingUploadPairList}"
                       AlternatingRowBackground="#e6e6e6"
                       AreRowDetailsFrozen="True"
                       Background="White"
                       CanUserReorderColumns="False"
                       CanUserResizeColumns="True"
                       CanUserSortColumns="True"
                       GridLinesVisibility="All"
                       HeadersVisibility="All"
                       SelectionMode="Single">
        <controls:DataGrid.Columns>
            <controls:DataGridTextColumn Header="Sync Type" Binding="{Binding Name}" IsReadOnly="True"/>
            <controls:DataGridTextColumn Header="Items Remaining" Binding="{Binding PendingItems}" IsReadOnly="True"/>
            <controls:DataGridTextColumn Header="% remaining" Binding="{Binding PendingPerc}" IsReadOnly="True"/>

        </controls:DataGrid.Columns>
    </controls:DataGrid>
</Grid>

Vm.PendingUploadPairList is some property of a viewmodel which is a List am trying to render in the data grid control. Each object in that list is in this form:

public class PendingUploadPair
{
  public string Name { get; set; }
  public string PendingItems { get; set; }
  public string PendingPerc { get; set; }
}

Now the problem in Xaml:

If I use the property x:Bind instead of Binding like this:

<controls:DataGridTextColumn Header="Sync Type" Binding="{x:Bind Name}" IsReadOnly="True"/>

It gives me compile time error:

'DataGridBoundColumn' does not contain a definition for 'BindingProperty' in the g.cs file of the View.

How do I use x:Bind here?


Solution

  • How do I use x:Bind here?

    You can't. x:Bind is not supported on DataGrid columns:

    No way to x:bind columns #2112