Data BindingExpression path error

2 Answers 60 Views
General Discussions GridView NavigationView (Hamburger Menu)
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Psyduck asked on 24 May 2021, 07:52 AM

Hello.

I'm making it using MVVM.

 

I've been asking questions before and got a lot of answers. Among them, a binding error is output.
On the actual screen, it is bound without any problem.
However, an error is displayed in the output.

Please refer to my example. The situation is like this.

StartView => MainWindow Open -> Hierarchy1 Open
You click on UserControl A and UserControl B once at a time.

The binding is bound. However, you will get an output error while debugging.

Usercontrol A.xaml contains UserAGridView and UserATextBlock.
Usercontrol B.xaml contains ComboData, ComboDataItem, OnClickButtonCommand, and ButtonText.

Whenever you click on a Navigation Item, you will get a bounding error in the output about what is bound to that Usercontrol.
(Bind value in debugging screen works normally)

The same phenomenon appeared in the button in the Column in UsercontrolA, and I tried using a proxy, but it was the same.

What is the problem?

 

Thanks.

 

2 Answers, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 27 May 2021, 07:12 AM

Hello KIM,

Let me start with a brief note about the binding to the SelectedItem of RadNavigationView. In the current setup the navigationview control is populated directly with RadNavigationViewItem controls which are visual UI elements. This means that when you select an item the SelectedItem value will be an object of type RadNavigationViewItem. The ContentControl in the navigationview's Content property is bound to the SelectedItem which means that it tries to get corresponding RadNavigationViewItem. In WPF there are a couple of options when you try to bind a visual element already added in the visual tree to another control's content. The first one is, an exception thrown because the same element cannot be added on two places in the visual tree. The second option is to move the UI element from its original element to the control that is bound to. In your situation, you are avoiding those scenarios by returning another visual in the ContentTemplateSelector. Anyway, this case is not recommended cause it can lead to different issues (like the binding errors for example). If you want to use the ContentTemplateSelector and bind to the SelectedItem of RadNavigationView I would suggest you to populate the control through its ItemsSource property as shown in its First Look demo, instead of adding the RadNavigationViewItems directly in XAML.

An alternative approach would be to use code-behind, instead of the binding to the SelectedItem. You can check this approach in the updated project attached in this reply.

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
answered on 31 May 2021, 02:46 AM | edited on 31 May 2021, 03:02 AM

Hello.

The overlapping problem was recognized and refreshed, but Data Error is output as it is. Likewise, bindings are linked.
For code-behind, I don't prefer code-behind, so I looked at the demo and made a sample file again. using MVVM.(The example you sent works well for my real project too!)

I thought I was avoiding the visual tree, but why is this?

In case of UserControl A and B, error output appears for all bindings.
In the case of UserControl C, when I refer to the DataContext of NavigationView, no error is output.

I think it's inefficient and wrong to put a RelativeSource on every UserControl binding item.

In addition, when creating a button in the GridView, I made two command methods, but this was not resolved either. Is this also resolved automatically when NavigationView.Content is resolved?

Thanks.

Martin Ivanov
Telerik team
commented on 02 Jun 2021, 12:10 PM

You can resolve the errors by using DynamicResource in the DataTemplates instead of StaticResource. For example:

<DataTemplate x:Key="ATemplate">

         <local:UserControlA DataContext="{DynamicResource MainWindowViewModel}" />
</DataTemplate>

 

Tags
General Discussions GridView NavigationView (Hamburger Menu)
Asked by
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Answers by
Martin Ivanov
Telerik team
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Share this question
or