Re: Dynamically adding a new widget in C++ code, and then using FindName() to get it
Posted: 20 Oct 2022, 12:02
I cannot overstate my appreciation for your on-going assistance. Thanks to your help maherne, I've managed to get the registration code to trigger. I also managed to place ElementRegistry in its own namespace (Ozmodiar) with the following change:
I've added the following cs dummy file:
While the Ozmodiar namespace seems to be accepted, I'm still getting the following errors preventing the xaml from being rendered in the blend designer:
I've attached the namespace to the canvas tag, and reference the dependency property as follows:
It seems I'm overlooking something, but I'm not clear as to what's missing...?
Gazoo
Code: Select all
NS_IMPLEMENT_REFLECTION( ElementRegistry, "Ozmodiar.ElementRegistry" )
Code: Select all
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Markup;
using Microsoft.Xaml.Behaviors;
namespace Ozmodiar
{
class ElementRegistry : DependencyObject
{
#region IsRegistered property
public static readonly DependencyProperty IsRegisteredProperty = DependencyProperty.Register(
"IsRegistered", typeof(bool), typeof(ElementRegistry), new PropertyMetadata(false));
public bool IsRegistered
{
get { return (bool)GetValue(IsRegisteredProperty); }
set { SetValue(IsRegisteredProperty, value); }
}
#endregion
}
}
Code: Select all
Error XLS0415 The attachable property 'IsRegistered' was not found in type 'ElementRegistry'. noesis_sandbox_gui
Error XDG0044 The local property "IsRegistered" can only be applied to types that are derived from "ElementRegistry".
Code: Select all
...
xmlns:local2="clr-namespace:Ozmodiar"
...
<Button Height="45" Width="88" Canvas.Left="274" Canvas.Top="50" Content="Ajajaja" local2:ElementRegistry.IsRegistered="True" />
Gazoo