开发者

DataGridTemplateColumn : Items collection must be empty before using ItemsSource.

Why is the error code :

        <dg:DataGrid  Name="dataGrid" AutoGenerateColumns="False"                                  
                HeadersVisibility="Column" SelectedIndex="-1" Margin="0,315,0,0" Background="#FF484040" BorderBrush="#FF484040">
        <dg:DataGrid.Columns>
            <dg:DataGridTextColumn Binding="{Binding IdBook}" Header="IdBook"></dg:DataGridTextColumn>
            <dg:DataGridTextColumn Binding="{Binding NameBook}" Header="NameBook"></dg:DataGridTextColumn>
            <dg:DataGridTextColumn Binding="{Binding Author}" Header="Author"></dg:DataGridTextColumn>
        </dg:DataGrid.Columns>

        <dg:DataGridTemplateColumn Header="Delete">

            <dg:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Button Style="{DynamicResource GlassButton}" Background="{DynamicResource DeleteButton}">

                    </Button>
                </DataTemplate>
            </dg:DataGridTemplateColumn.CellTemplate>

            </dg:DataGridTemplateColumn>
    </dg:DataGrid>

The following code is correct :

        <dg:DataGrid  Name="dataGrid" AutoGenerateColumns="False"                                  
                HeadersVisibility="Column" SelectedIndex="-1" Margin="0,315,0,0" Background="#FF484040" BorderBrush="#FF484040">
        <dg:DataGrid.Co开发者_如何学运维lumns>
            <dg:DataGridTextColumn Binding="{Binding IdBook}" Header="IdBook"></dg:DataGridTextColumn>
            <dg:DataGridTextColumn Binding="{Binding NameBook}" Header="NameBook"></dg:DataGridTextColumn>
            <dg:DataGridTextColumn Binding="{Binding Author}" Header="Author"></dg:DataGridTextColumn>
        </dg:DataGrid.Columns>

    </dg:DataGrid>

But I can not be add button to datagrid


Keep template column inside DataGrid.Columns.

     <dg:DataGrid  Name="dataGrid" AutoGenerateColumns="False"                                  
            HeadersVisibility="Column" SelectedIndex="-1" Margin="0,315,0,0" Background="#FF484040" BorderBrush="#FF484040">
    <dg:DataGrid.Columns>
        <dg:DataGridTextColumn Binding="{Binding IdBook}" Header="IdBook"></dg:DataGridTextColumn>
        <dg:DataGridTextColumn Binding="{Binding NameBook}" Header="NameBook"></dg:DataGridTextColumn>
        <dg:DataGridTextColumn Binding="{Binding Author}" Header="Author"></dg:DataGridTextColumn>
       <dg:DataGridTemplateColumn Header="Delete">
             <dg:DataGridTemplateColumn.CellTemplate>
                 <DataTemplate>
                       <Button Style="{DynamicResource GlassButton}" Background="{DynamicResource DeleteButton}">
                         </Button>
            </DataTemplate>
        </dg:DataGridTemplateColumn.CellTemplate>
        </dg:DataGridTemplateColumn>
    </dg:DataGrid.Columns>
  </<dg:DataGrid>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜