Closed JesFo closed 1 year ago
Hey Jesse!
It seems that you are assigning the new offset to a local field of the LabelControl
and not the Margin
control within it.
You might want to change your code to be like this:
internal class LabelControl: SimpleControl
{
private readonly TextBlock _label;
private readonly TextBlock _value;
private readonly Margin _margin;
public LabelControl()
{
_label = new TextBlock(); //┤
_value = new TextBlock();
_margin = new Margin
{
Offset = new Offset(0,0,0,0),
Content = new Overlay
{
TopContent = _label,
BottomContent = _value
}
};
Content = _margin;
}
public Offset Margin
{
get => _margin.Offset;
set => _margin.Offset = value;
}
public string Label
{
get => _label.Text;
set => _label.Text = value;
}
public string Value
{
get => _value.Text;
set => _value.Text = value;
}
}
This way you "bind" the Offset
of the internal Margin
control to the Offset
of your LabelControl
.
Please let me know if that worked, as I did not run/test it.
Hey Jesse!
It seems that you are assigning the new offset to a local field of the
LabelControl
and not theMargin
control within it.You might want to change your code to be like this:
internal class LabelControl: SimpleControl { private readonly TextBlock _label; private readonly TextBlock _value; private readonly Margin _margin; public LabelControl() { _label = new TextBlock(); //┤ _value = new TextBlock(); _margin = new Margin { Offset = new Offset(0,0,0,0), Content = new Overlay { TopContent = _label, BottomContent = _value } }; Content = _margin; } public Offset Margin { get => _margin.Offset; set => _margin.Offset = value; } public string Label { get => _label.Text; set => _label.Text = value; } public string Value { get => _value.Text; set => _value.Text = value; } }
This way you "bind" the
Offset
of the internalMargin
control to theOffset
of yourLabelControl
.Please let me know if that worked, as I did not run/test it.
This worked fine. Thank you for your quick response.
I have a custom control for labels with an equal spacing using the
Margin
control:Changing parameters
Label
andValue
within each instance after initialization changes the text within the accordingly assignedTextBlock
controls just fine (e.g,mylabelcontrol.Value = "new value"
,mylabelcontrol.Label = "new label"
). However, assigning a new Offset for the Margin control after initialization yields no result (e.g:mylabelcontrol.Margin = new Offset(1,2,3,4)
). Is this behaviour by design?