如何显示“未找到项目"在数据网格中 [英] How to Display "No Items found" in a Datagrid

查看:36
本文介绍了如何显示“未找到项目"在数据网格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

               <dg:DataGrid.Resources>
                        <ViewModel:SmartMessenger  x:Key="Noitemsfound">
                        </ViewModel:SmartMessenger>
                      </dg:DataGrid.Resources>
                 <dg:DataGrid.RowDetailsTemplate>
                        <DataTemplate>
                          <StackPanel>`enter code here`
                            <TextBlock Text="{Binding Source={StaticResource         Noitemsfound }, Path=pNorecords,Mode=TwoWay}" />
                          </StackPanel>
                        </DataTemplate>
                 </dg:DataGrid.RowDetailsTemplate>

在这里,我试图绑定一个文本块,当数据网格中没有项目时,该文本块将显示一条消息.我正在使用 VS 2008 Express 版.问题是我无法将属性 Noitemsfound 与类 SmartMessenger 后面的代码绑定......这里缺少什么???

Here i am trying to bind a textblock that will display a message when there are no items in the datagrid . I am using VS 2008 Express edition. The problem is am not able to bind the property Noitemsfound with a code behind class SmartMessenger ... Whats missing here???

推荐答案

如果您只想在没有项目时在数据网格中显示一条消息 - 您可以使用样式来实现.将此样式放在您的 App.xaml 资源或至少在您的数据网格资源中.

if you just want to display a message in your datagrid when there are no items - you can do this with a style. Put this style in your App.xaml Resources or at least in your datagrid Resources.

    <Style x:Key="{x:Type ItemsControl}" TargetType="{x:Type ItemsControl}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}}" Value="0">
            <Setter Property="Background">
                <Setter.Value>
                    <VisualBrush Stretch="None">
                        <VisualBrush.Visual>
                            <TextBlock Text="no items" 
                                       FontFamily="{StaticResource FontFamily}"
                                       FontSize="{StaticResource FontSize}"/>
                        </VisualBrush.Visual>
                    </VisualBrush>
                </Setter.Value>
            </Setter>
        </DataTrigger>
        <DataTrigger Binding="{Binding Items, RelativeSource={RelativeSource Self}}" Value="{x:Null}">
            <Setter Property="Background">
                <Setter.Value>
                    <VisualBrush Stretch="None">
                        <VisualBrush.Visual>
                            <TextBlock Text="no items" 
                                       FontFamily="{StaticResource FontFamily}"
                                       FontSize="{StaticResource FontSize}"/>
                        </VisualBrush.Visual>
                    </VisualBrush>
                </Setter.Value>
            </Setter>
        </DataTrigger>
    </Style.Triggers>
</Style>
<Style x:Key="{x:Type DataGrid}" TargetType="{x:Type DataGrid}" BasedOn="{StaticResource {x:Type ItemsControl}}">
</Style>

这篇关于如何显示“未找到项目"在数据网格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆