Binding NavigationBar ItemsSource does not work

Navigation for WPF Forum

Posted 8 years ago by Manuel Eisenschink - Twisted Arts
Version: 15.1.0624
Avatar

Hello,

I am struggling to get this working for way too long now. All I want is to bind an ObservableCollection of type "MonitorModule" to my NavigationBar. This is a custom class with INotifyPropertyChanged implemented correctly.

As I would think all I have to do is what I'm currently trying:

            <navigation:NavigationBar x:Name="NavBar" Grid.Column="0" ContentWidth="180" IsMinimizable="True" IsCustomizationEnabled="False" BorderThickness="0"
                                  SelectionChanged="NavBar_OnSelectionChanged" Grid.RowSpan="3" IsMinimized="False" Title="Modules" ItemsSource="{Binding Modules}">
                <navigation:NavigationBar.ItemTemplate>
                    <DataTemplate DataType="{x:Type monitor:MonitorModule}">
                        <navigation:NavigationPane ImageSourceLarge="{Binding LargePanelIcon}" Header="{Binding Title}" ImageSourceSmall="{Binding SmallPanelIcon}" />
                    </DataTemplate>
                </navigation:NavigationBar.ItemTemplate>
            </navigation:NavigationBar>

 But when I test my application all I see is a lot of nothing. The pane is empty. No icon, no title - but it exists and can be selected. When I click it, the "module" is being shown in the content of the NavBar (the module is a UserControl with a set attribute of ContentProperty).

But I'd want to actually show the content by using the property "PanelContent", which doesn't work either.

What am I doing wrong? Isn't this the general WPF approach of using custom data? Is it a bug or am I completely wrong? If this doesn't work soon, I'll make it on my own...

 

Thank you!

Greetings
Manuel

Comments (3)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Manuel,

What you are doing in the XAML won't work correctly because NavigationPane is being created as the item container for the NavigationBar, and I think you are effectively nesting your own NavigationPane inside our generated container NavigationPane.  If you want MVVM to work, you would need to either:

1) Inherit NavigationBar and override PrepareContainerForItemOverride, where element is a generated NavigationPane container and item is your MonitorModule object.  Then programmatically bind properties like ImageSourceLarge on the NavigationPane to the related MonitorModule object property.  Finally clear those bindings in a ClearContainerForItemOverride override.

or

2) You might be able to set the NavigationBar.ItemContainerStyle and make a Style that targets NavigationPane (since it is the container).  Then make Setters in that Style for properties like ImageSourceLarge and make the setter values be bindings to the related MonitorModule object properties.

Either of those should help get you going.


Actipro Software Support

Posted 8 years ago by Manuel Eisenschink - Twisted Arts
Avatar

Yeah I know that it's just a container. I've seen the style approach in your samples, but there you bind XML data which obviously has a different scope and thus kinda confused me. When I tried the same thing, I ended up with this empty pane (no text, no icon). Obviously it doesn't get where to bind to and I don't see any way to use the ItemsSource elements as DataContext for the style.

Like said, in your example you use XML which obviously works a bit different since you can simply use the XPath property on bindings. Might be a nice idea to include a MVVM example in the future, after all I would have expected it to be easier to use MVVM with NavBar.

I'll go with the programmatic approach then, I guess. Should work at least.

Greetings,

Manuel

[Modified 8 years ago]

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Manual,

If you want to throw together a new simple sample project showing what you are doing (given any changes per our previous reply) and how it's not rendering how you'd expect, you can email our support address with it and we'll be happy to take a look.  In your email, please reference this thread and rename the .zip file extension so it doesn't get spam blocked.


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.