This is a migrated thread and some comments may be shown as answers.

Set "Visibility" is "Collapsed" in ListBox.ItemContainerStyle

1 Answer 471 Views
VirtualizingWrapPanel
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 01 Mar 2013, 09:32 AM

Hi,telerik:
I want to show some images in the listbox with VirtualizingWrapPanel and some will not. It depends on the property(IsDefault) that i have defined.
here is the code:

<P><ListBox.ItemContainerStyle><BR>               
<Style TargetType="{x:Type
ListBoxItem}"><BR>                                     
<Style.Triggers><BR>                       
<DataTrigger Binding="{Binding IsDefault}"
Value="true"><BR>                           
<Setter Property="Visibility"
Value="Collapsed"/><BR>                       
</DataTrigger></P>
<P>                       </P>
<P>                   
</Style.Triggers><BR>               
</Style><BR>           
</ListBox.ItemContainerStyle><BR></P>

but even through the value of the "IsDefault" is set to "true",the listboxitem still display in the listbox ,and the item is blank.
How do I do before they can get the effect I want?
Thanks and Regards,
Bill.

1 Answer, 1 is accepted

Sort by
0
Chuck
Top achievements
Rank 1
answered on 29 Jun 2015, 06:44 PM

I know this is an old post, but this might help someone. If "IsDefault" isn't a dependency property, make it one with a callback. Similar to:

public bool ShowHidden
{
    get { return (bool)GetValue(ShowHiddenProperty); }
    set { SetValue(ShowHiddenProperty, value); }
}
 
public static readonly DependencyProperty ShowHiddenProperty =
    DependencyProperty.Register("ShowHidden", typeof(bool), typeof(TileLoader), new PropertyMetadata(false, ShowHidden_Callback));
 
private static void ShowHidden_Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    TileLoader _this = d as TileLoader;
    if (!_this.dpConstructorDone) return; // prevent constructor doing a refresh (and getting an error)

                                           // if you set the property value in the constructor on load

    bool value = (bool)e.NewValue;
    // do something with value here if you want
    _this.View.CollectionView.Refresh();
}

Then create a collection view with a filter for your ListBox

View.CollectionView = CollectionViewSource.GetDefaultView(View.Images);
View.CollectionView.Filter = oImage =>
{
    var image = (ImageDTO)oImage;
    if (image.IsHidden && !ShowHidden) return false;
    if (string.IsNullOrWhiteSpace(Search))
        return true;
    return image.Name.ToLower().Contains(Search.ToLower());
};

I also have a Search textbox, so my filter includes that. So when you refresh your collection view, Then you won't be displaying your hidden items (and there won't be blank boxes either.)

Tags
VirtualizingWrapPanel
Asked by
Bill
Top achievements
Rank 1
Answers by
Chuck
Top achievements
Rank 1
Share this question
or