WPF - a preload image or template before TabItem load
I have a listbox in TabContorol that bind to a database, it takes a little while to load. 开发者_开发百科i want show a preload image or template before TabItem and listbox loaded and after load became complete the preload image be diasapear. help me plz
I would use a Trigger in the ListBox.Style
, and if the ItemSource is null I would rewrite the ListBox.Template
using a Loading Image instead of the regular ListBox template.
Here's an example:
<Style TargetType="{x:Type ListBox}">
<Style.Triggers>
<DataTrigger Property="{Binding MyList}" Value="{x:Null}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Image Source="loadingImage.gif" />
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
I didn't run this through a compiler so I might have some syntax errors, but it should point you in the right direction.
精彩评论