【问题标题】:Show only allowed data in WPF Listbox Databinding在 WPF 列表框数据绑定中仅显示允许的数据
【发布时间】:2011-04-18 00:32:14
【问题描述】:

我目前有一个列表框:

<ListBox HorizontalAlignment="Left"
         ItemsSource="{Binding Data, ElementName=bookingDomainDataSource}"
         Margin="158,134,0,45"
         x:Name="bookingListBox"
         Width="429"
         SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay, ElementName=bookingComboBox}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Path=userId}"
                           Width="100" />
                <TextBlock Text="{Binding Path=bookingName}"
                           Width="100" />
                <TextBlock Text="{Binding Path=bookingDate}"
                           Width="100" />
                <TextBlock Text="{Binding Path=showId}"
                           Width="100" />
                <TextBlock Text="{Binding Path=paymentId}"
                           Width="100" />
                <TextBlock Text="{Binding Path=ticketId}"
                           Width="100" />
                <TextBlock Text="{Binding Path=ticketQuantity}"
                           Width="100" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

我只想显示itemssource 中具有特定userId 的行,我该怎么做?

谢谢。

【问题讨论】:

    标签: c# wpf silverlight xaml data-binding


    【解决方案1】:

    我认为最好的解决方案是在到达前端之前过滤数据源。

    【讨论】:

    • 我将如何过滤数据,我正在使用 WCF RIA 服务
    • 我不确定您的情况,但是无论您在哪里调用 Web 服务,无论是在后面的代码中还是在 ViewModel 中,添加类似的内容: bookingDomainDataSource = from b in bookingDomainDataSource其中 b.UserID == [valuehere] 选择 b;
    • 您似乎写的确实有道理,但我无法让它发挥作用。 bookingDomainDataSource = from b in boo... 会像那样工作吗?
    • 取决于你的情况。确保您在顶部有“使用 System.Linq”,并且 bookingDomainDataSource 是一个可枚举的对象。我建议对“linq to objects”做一些简单的阅读。
    • 我已经弄明白了,我用过:EntityQuery
    【解决方案2】:

    你想define a filter for your listview

    Uodate:抱歉错过了 silverlight 标签。但是CollectionViewSource 应该仍然对您有用。这是一个示例using the CollectionViewSource in Silverlight

    【讨论】:

    • 您发布的示例似乎不适用于我的 silverlight 应用程序。 GetDefault 不能使用,因为它不存在。我正在使用 system.windows.data
    猜你喜欢
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 2010-12-15
    • 1970-01-01
    相关资源
    最近更新 更多