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
如图:数据有的,就是不显示:
整个文件:
<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>