【发布时间】:2018-10-18 09:32:51
【问题描述】:
我有一个 WPF DataGrid,当其中没有记录时,我想在其中显示一条消息“无数据”。所以我已经完成了 pcajer 提供的答案中here 的解释,但是当数据网格显示没有数据时,消息不会显示。我想我遇到了AncestorType 的问题,我认为我没有正确指定,但我不知道如何解决这个问题。我完全不明白AncestorType 的工作原理......
在我的代码下面:
<Window x:Class="My.Apps.WPF.Test.wMain"
xmlns:local="clr-namespace:My.Apps.WPF.Test">
<dg:DataGrid.Style>
<Style TargetType="dg:DataGrid">
<Setter Property="RowDetailsVisibilityMode" Value="Collapsed"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.IsRecordExists,
RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type local:wMain}}}" Value="false">
<Setter Property="RowHeight" Value="0"></Setter>
<Setter Property="RowDetailsVisibilityMode" Value="Visible"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</dg:DataGrid.Style>
<!-- Missatge quan no hi ha documents pel procés seleccionat -->
<dg:DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="No hi ha documents disponibles pel procés seleccionat" Width="400"></TextBlock>
</StackPanel>
</DataTemplate>
</dg:DataGrid.RowDetailsTemplate>
</Window>
代码隐藏 (XAML.cs):
namespace My.Apps.WPF.Test
{
public partial class wMain : ViewBaseControl
{
}
}
【问题讨论】:
-
这是 wMain 类中的 IsRecordExists 属性吗?
标签: c# wpf .net-3.5 wpfdatagrid