View Issue Details

IDProjectCategoryView StatusLast Update
0001937NoesisGUIC# SDKpublic2022-11-07 17:14
ReporterFaerdan Assigned Tosfernandez  
PrioritynormalSeverityfeature 
Status feedbackResolutionopen 
Product Version3.0.10 
Target Version3.1.7 
Summary0001937: Expose FrameworkElement AddLogicalChild(object) and RemoveLogicalChild(object) methods
Description

FrameworkElement.AddLogicalChild(object) and FrameworkElement.RemoveLogicalChild(object) allow for management of the logical tree.

https://docs.microsoft.com/en-us/dotnet/api/system.windows.frameworkelement.addlogicalchild?view=net-5.0
https://docs.microsoft.com/en-us/dotnet/api/system.windows.frameworkelement.removelogicalchild?view=net-5.0

These methods are required to allow logical tree based binding within dependency property values.

Example (works in WPF):
<common:TextContentControl Text="((holdingsScreen_txt_title))">
<common:TextContentControl.TextParameters>
<common:ParameterViewData Key="key2" Value="{Binding CurrenciesData.Fuel}" />
</common:TextContentControl.TextParameters>
</common:TextContentControl>

private static void OnTextParametersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is TextContentControl textContentControl)
{
if (e.OldValue != null)
{
textContentControl.RemoveLogicalChild(e.OldValue);
}
if (e.NewValue != null)
{
textContentControl.AddLogicalChild(e.NewValue);
}
}
}

PlatformAny

Activities

Faerdan

Faerdan

2022-01-07 10:56

reporter   ~0007717

Any update on when this feature will be added? I've tried the recommended workaround, binding to an ElementName, but this doesn't work either. The Value properties below are empty in the code behind.

<controls:TextControl x:Name="label_level" Text="((txt.heroUnitsScreen.label_level))" >
<controls:TextControl.TextParameters>
<common:ParameterViewData Key="currentLevel" Value="{Binding DataContext.HeroUnit.Level, ElementName=label_level}"/>
<common:ParameterViewData Key="actualWidth" Value="{Binding ActualWidth, ElementName=label_level}"/>
</controls:TextControl.TextParameters>
</controls:TextControl>

public static readonly DependencyProperty TextParametersProperty =
DependencyProperty.Register(nameof(TextParameters), typeof(ParameterCollection), typeof(TextControl),
new PropertyMetadata(null, OnTextParametersChanged));

public class ParameterCollection : FreezableCollection<ParameterViewData> { }

public class ParameterViewData : Freezable, ITextParameter
{
    public string Key
    {
        get { return (string)GetValue(KeyProperty); }
        set { SetValue(KeyProperty, value); }
    }
    public static readonly DependencyProperty KeyProperty = DependencyProperty.Register(
        nameof(Key), typeof(string), typeof(ParameterViewData),
        new PropertyMetadata(null));
    public object Value
    {
        get { return (object)GetValue(ValueProperty); }
        set { SetValue(ValueProperty, value); }
    }
    public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
        nameof(Value), typeof(object), typeof(ParameterViewData),
        new PropertyMetadata(null));

#if !NOESIS
protected override Freezable CreateInstanceCore()
{
return new ParameterViewData();
}
#endif

sfernandez

sfernandez

2022-01-10 18:18

manager   ~0007720

Hi, this issue was not planned for the next version yet, I'll add it to our roadmap.

I just verified that the workaround works as expected if you use Animatable as the base class for the params class:

    public class ParameterViewData : Animatable
{
public string Key
{
get { return (string)GetValue(KeyProperty); }
set { SetValue(KeyProperty, value); }
}
public static readonly DependencyProperty KeyProperty = DependencyProperty.Register(
nameof(Key), typeof(string), typeof(ParameterViewData),
new PropertyMetadata(null));
public object Value
{
get { return (object)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
nameof(Value), typeof(object), typeof(ParameterViewData),
new PropertyMetadata(null));
}

public class ParameterCollection : FreezableCollection<ParameterViewData> { }

public class TextControl : ContentControl
{
    public ParameterCollection TextParameters
    {
        get { return (ParameterCollection)GetValue(TextParametersProperty); }
        set { SetValue(TextParametersProperty, value); }
    }
    public static readonly DependencyProperty TextParametersProperty = DependencyProperty.Register(
        "TextParameters", typeof(ParameterCollection), typeof(TextControl),
        new PropertyMetadata(null, OnTextParametersChanged));
    ...
}</pre>

Issue History

Date Modified Username Field Change
2021-03-10 16:19 Faerdan New Issue
2021-03-10 17:00 sfernandez Assigned To => sfernandez
2021-03-10 17:00 sfernandez Status new => assigned
2021-03-10 17:00 sfernandez Target Version => 3.0.11
2021-03-15 17:10 jsantos Target Version 3.0.11 => 3.0.12
2021-05-04 02:41 jsantos Target Version 3.0.12 => 3.0.13
2022-01-07 10:56 Faerdan Note Added: 0007717
2022-01-10 18:18 sfernandez Status assigned => feedback
2022-01-10 18:18 sfernandez Note Added: 0007720
2022-01-10 18:18 sfernandez Target Version => 3.1.3
2022-02-14 17:48 sfernandez Target Version 3.1.3 => 3.1.4
2022-03-17 21:31 sfernandez Target Version 3.1.4 => 3.1.5
2022-06-24 17:21 sfernandez Target Version 3.1.5 => 3.1.6
2022-11-07 17:14 sfernandez Target Version 3.1.6 => 3.1.7