DataGridTemplateColumn :使用 ItemsSource 之前,Items 集合必须为空。
为什么是错误代码:
<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>
以下代码是正确的:
<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:DataGrid>
但我无法将按钮添加到数据网格
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.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:DataGrid>
But I can not be add button to datagrid
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将模板列保留在 DataGrid.Columns 中。
Keep template column inside DataGrid.Columns.