我得到了这个XAML代码:
<Grid>
<Grid.Resources>
<XmlDataProvider x:Key="SlData" Source="test.xml" XPath="/sls/sl"/>
</Grid.Resources>
<DataGrid x:Name="dgridEmp" Style="{DynamicResource Datag1}" DataContext="{StaticResource SlData}" ItemsSource="{Binding XPath=/sls/sl}" AutoGenerateColumns="False" Margin="1,145,7,-506" FontSize="15" IsReadOnly="True" >
<DataGrid.Columns>
<DataGridTextColumn Header="bencd" Binding="{Binding XPath=benCd}" Width="72" >
</DataGridTextColumn>
<DataGridTextColumn Header="slpos" Binding="{Binding XPath=slpos}" Width="40" />
<DataGridTextColumn Header="slNr" Binding="{Binding XPath=slNr}" Width="72" />
<DataGridTextColumn Header="stufe" Binding="{Binding XPath=stufe}" Width="40" />
<DataGridTextColumn Header="spJn" Binding="{Binding XPath=spJN}" Width="40" />
<DataGridTextColumn Header="slNrHpt" Binding="{Binding XPath=slNrHpt}" Width="72" />
<DataGridTextColumn Header="me" Binding="{Binding XPath=menge}" Width="30" />
<DataGridTextColumn Header="bez" Binding="{Binding XPath=bez}" Width="250" />
<DataGridTextColumn Header="bezkurz" Binding="{Binding XPath=bezkurz}" Width="100" />
<DataGridTextColumn Header="bezE" Binding="{Binding XPath=bezE}" Width="100" />
</DataGrid.Columns>
</DataGrid>
</Grid>
我想要的是向标题&#34; bencd&#34;添加一个Button Right到Datagridtextcolumn,使它看起来像这样(使用这个蓝色过滤器按钮在正确的位置):
答案 0 :(得分:1)
您可以将Header
属性设置为您想要的任何元素,例如StackPanel
TextBlock
和Button
:
<DataGridTextColumn Binding="{Binding XPath=benCd}" Width="72" >
<DataGridTextColumn.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="bencd"/>
<Button Content="Filter" />
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
当然,您需要设置Button
的样式,使其看起来像&#34;过滤器&#34;按钮,但这是另一个故事。