I have a silverlight application in which I display items in a list box. I want to hide some items based on a condition, like some value of a string.
My xaml looks like this:
<ListBox
ItemsSource="{Binding DashboardTypes}"
SelectedItem="{Binding SelectedDashboardCategory,Mode=TwoWay}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Style="{StaticResource ListBoxStyleAttribute}"
Margin="2"
ItemContainerStyle="{StaticRes开发者_如何转开发ource ListBoxItemStyle}" />
You'll need to set up an ItemTemplate
to describe your items and then add a binding on that for the Visibility property that controls when items are visible or not. I suspect that you'll need a converter to actually implement the rule for when an item should be visible.
There is a Stack Overflow question that covers something similar but in WPF. It should give you some pointers that will help you in implementing this.
精彩评论