I have a statusbar, which will contain some dynamic statusbaritems and some "hard-coded" statusbaritems. For some reason the dynamic status bar items are not displayed, even thought the binding with the ViewModel property is done and I can see the items using Live Visual Tree
This is the statusbar
<StatusBar x:Name="StatusBar" Grid.Column="2" Grid.Row="1" ItemsSource="{Binding}">
<StatusBar.Background>
<SolidColorBrush Color="White" Opacity="0.5"/>
</StatusBar.Background>
<StatusBarItem Height="60" Width="120" HorizontalAlignment="Right">
<Image Source="Logo.png" ></Image>
</StatusBarItem>
<Separator></Separator>
<StatusBar.ItemTemplate>
<DataTemplate>
<TextBlock Text="ASDF"></TextBlock>
</DataTemplate>
</StatusBar.ItemTemplate>
</StatusBar>
This is the statusbar at runtime.
As you can see there are 5 items that are visible and 2 items from the observable collection that do not render on the UI.
The green/blue part is visible, the rest of the StatusBar space is taken by the last separator. My dynamic items are no where to be found.
Any ideas? Can I make both dynamic/static items work in the same StatusBar? Or do I need to add 2 statusbar one for dynamic and the other one for static content.
Can I make both dynamic/static items work in the same StatusBar?
No. You cannot both bind to an ItemsSource
and add static objects to the Items
collection.
If your binding would work, you would get an InvalidOperationException
saying that 'Items
collection must be empty before using ItemsSource
.'
What you should do is to add your static items to the source collection in your view model.