arvenyon
Topic Author
Posts: 4
Joined: 10 Sep 2024, 12:52

Binding failed when re-routing Content Property of UserControl

12 Sep 2024, 13:26

Hey folks,
I am trying to re-route the content of a usercontrol to a custom dependency property and bind it to my own contentpresenter.
As far as I am aware I'm doing it the intended way, as stated here in the binding documentation: https://www.noesisengine.com/docs/Gui.C ... orial.html
Could it be that the re-routing is an issue or am I just dense right now?

The error:
[NOESIS] Binding failed: Path=InnerContent, Source=Testing.DetailsPanel('Root'), Target=ContentPresenter('_InnerContentPresenter'), TargetProperty=ContentControl.Content
UnityEngine.Debug:LogError (object,UnityEngine.Object)
[NOESIS] Can't solve PropertyPath: Type 'Testing.DetailsPanel' does not contain a property named 'InnerContent' // <----- as far as I am aware, it does?
Here's my very basic XAML:
<UserControl x:Class="Testing.DetailsPanel"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Name="Root">
	<!-- Root Grid That Has The Base Texture As Background -->
	<Grid x:Name="_RootGrid"
		  Margin="8"
		  Width="400"
		  Height="600">
		<Grid.Background>
			<!--<ImageBrush Source="" />-->
			<SolidColorBrush Color="#FFFFFF" />
		</Grid.Background>

		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<!-- LOGO -->
			<RowDefinition Height="*" />
			<!-- CONTENT -->
		</Grid.RowDefinitions>
		
		<ContentPresenter x:Name="_InnerContentPresenter" 
						  Content="{Binding InnerContent, ElementName=Root}" 
						  Grid.Row="1" />
		
	</Grid>
</UserControl> 
And the respective code behind:
#if UNITY_5_3_OR_NEWER
    #define NOESIS
    using Noesis;
#else
    using System.Windows;
    using System.Windows.Controls;
#endif

namespace Testing
{
    [ContentProperty(nameof(InnerContent))]
    public partial class DetailsPanel: Noesis.UserControl
    {
        public static readonly DependencyProperty InnerContentProperty =
            DependencyProperty.Register(nameof(InnerContent), typeof(object), typeof(DetailsPanel), new PropertyMetadata(null));

        public object InnerContent
        {
            get { return GetValue(InnerContentProperty); }
            set { SetValue(InnerContentProperty, value); }
        }

        public DetailsPanel()
        {
            InitializeComponent();
        }

    #if NOESIS
        private void InitializeComponent()
        {
            NoesisUnity.LoadComponent(this);
        }
    #endif
    };
}
 
User avatar
sfernandez
Site Admin
Posts: 3154
Joined: 22 Dec 2011, 19:20

Re: Binding failed when re-routing Content Property of UserControl

17 Sep 2024, 20:40

It is weird, I tried your user control (xaml + cs) in Noesis 3.2.4 and it works as expected without any binding warning and showing whatever elements I set in the InnerContent property.
What version of Noesis are you using?

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests