tiankong1213 2019-03-19 14:02 采纳率: 50%
浏览 468
已采纳

WPF .Net FameWork4.6.1 DataGrid 数据要点击才显示

DataGrid 数据要点击才显示然后 点击其他地方又隐藏了

是照着微软例子写的:https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/getting-started/walkthrough-my-first-wpf-desktop-application
我的项目源代码:

链接:https://pan.baidu.com/s/1EAu-NoczTAPpOdTadHQR_Q

提取码:fntw

如图:数据有的,就是不显示:

图片说明
图片说明

DataGrid 代码:
图片说明

整个文件:
<Page x:Class="ExpenseIt.ExpenseReportPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:ExpenseIt"
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
      Title="ExpenseIt - View Expense">

    <Grid>
        <Grid.Background>
            <ImageBrush ImageSource="watermark.png"/>
        </Grid.Background>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="230"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Label Grid.Column="1" Style="{StaticResource headerTextStyle}">
            Expen Report For:
        </Label>
        <Grid Margin="10" Grid.Column="1" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition />
            </Grid.RowDefinitions>
            <StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Orientation="Horizontal" >
                <Label Style="{StaticResource labelStyle}">Name:</Label>
                <Label Style="{StaticResource labelStyle}" Content="{Binding XPath=@Name}"></Label>
            </StackPanel>
            <!-- DepartMent -->
                <StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Orientation="Horizontal">
                <Label Style="{StaticResource labelStyle}">DeparTment</Label>
                <Label Style="{StaticResource labelStyle}" Content="{Binding XPath=@Department}"></Label>
            </StackPanel>
            <Grid Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" VerticalAlignment="Top"
                  HorizontalAlignment="Left">
                <!--Templates to Diaplay Expense Report data-->
                <Grid.Resources>
                    <!--Reason item Template-->
                    <DataTemplate x:Key="typeItemTemplate">
                        <Label Content="{Binding XPath=@ExpenseType}"/>
                    </DataTemplate>
                    <!--Amount item template-->
                    <DataTemplate x:Key="amountItemTemplate">
                        <Label Content="{Binding XPath=@ExpenseAmount}"/>
                    </DataTemplate>
                </Grid.Resources>
                <!-- Expense Type and Amount table -->
                <DataGrid ItemsSource="{Binding XPath=Expense}" ColumnHeaderStyle="{StaticResource columnHeaderSyle}"
                    AutoGenerateColumns="False" RowHeaderWidth="0" RowHeight="50">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Header="ExpenseType" CellEditingTemplate="{StaticResource typeItemTemplate}"/>
                        <DataGridTemplateColumn Header="Amount" CellEditingTemplate="{StaticResource amountItemTemplate}"/>
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
        </Grid>
    </Grid>
</Page>

  • 写回答

1条回答 默认 最新

  • hxycsdn9159 2019-03-22 17:07
    关注

    图片说明
    换成CellTemplete就可以了,CellEditingTemplete只有在“编辑”状态的时候才生效,你点击的时候控件的状态变为”编辑“状态,所以点击的时候可见

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改