Datagrid WPF问题

时间:2017-08-27 19:37:17

标签: wpf xaml datagrid

我有一个绑定到XML数据集的Datagrid。一切都很好,但我想添加一个图像列,为每行显示不同的图像。问题是当我添加一个图像源时,它会为所有行设置它,而不仅仅是一个特定的行。

 In the same Datagrid, I have a Qty column that is blank, and I need it to be an int 0. Then when the user presses a "purchase" button it adds 1 to it, like an inventory amount. Any idea how to add that into the column? Almost like a textbox in each row.

这是一个用于视觉参考的图像。 https://pasteboard.co/GHDbdhS.png

这是XAML,我没有代码,因为所有内容都在XML文件中。

<DataGrid x:Name="tab_mounts" IsTextSearchEnabled="True" HorizontalAlignment="Left" Height="572" Margin="13,209,0,0" VerticalAlignment="Top" Width="618" FontFamily="/Player Workbench;component/Fonts/#UnZialish" AutoGenerateColumns="False" ItemsSource="{Binding XPath=/MountInfo/Mount}" CanUserReorderColumns="True" CanUserResizeColumns="False" FontSize="16" MinColumnWidth="1" BorderBrush="{x:Null}" Foreground="#FFB3B3B3" HorizontalGridLinesBrush="{x:Null}" VerticalGridLinesBrush="{x:Null}" Background= "Transparent" CanUserResizeRows="False" RowHeaderWidth="0" FontWeight="Normal" CanUserAddRows="True" VerticalContentAlignment="Center" GridLinesVisibility="None" >
                    <DataGrid.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFCAA201"/>
                    </DataGrid.Resources>
                    <DataGrid.DataContext>
                        <Binding Source="{StaticResource Mount}"/>
                    </DataGrid.DataContext>
                    <DataGrid.RowBackground>
                        <ImageBrush/>
                    </DataGrid.RowBackground>
                    <DataGrid.AlternatingRowBackground>
                        <ImageBrush/>
                    </DataGrid.AlternatingRowBackground>
                    <DataGrid.ColumnHeaderStyle>
                        <Style TargetType="{x:Type DataGridColumnHeader}">
                            <Setter Property="Background" Value="{StaticResource PrimaryBrush}"/>
                            <Setter Property="Foreground" Value="{StaticResource PrimaryFont}" />
                            <Setter Property="HorizontalContentAlignment" Value="Center" />
                            <Setter Property="VerticalContentAlignment" Value="Center" />
                        </Style>
                    </DataGrid.ColumnHeaderStyle>
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Width="84">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Image Source="/Images/i_camel.png" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Header="Name" Binding="{Binding XPath=Item}"/>
                        <DataGridTextColumn Header="Cost" Binding="{Binding XPath=Cost}" />
                        <DataGridTextColumn Header="Speed" Binding="{Binding XPath=Speed}" />
                        <DataGridTextColumn Header="Capacity" Binding="{Binding XPath=Capacity}" Width="125" />
                        <DataGridTextColumn Header="Qty"/>
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
        </TabItem>

0 个答案:

没有答案