Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The textbox control does not display when used as an Adorner #16977

Closed
maoyy opened this issue Sep 10, 2024 · 5 comments
Closed

The textbox control does not display when used as an Adorner #16977

maoyy opened this issue Sep 10, 2024 · 5 comments
Labels

Comments

@maoyy
Copy link

maoyy commented Sep 10, 2024

The textbox control does not display when used as an Adorner。Replacing the textbox with a textblock or button control will display it normally。

Avalonia version:11.1.3
operating system:windows10

test code:
var text = new TextBox(); //TextBlock
text.Text = "asdfasdfsdf";
text.Background = Brushes.Red;
text.Width = 10;
text.Height = 10;

AdornerLayer.SetAdorner(this, text);
AdornerLayer.SetIsClipEnabled(text, false);

Sorry, I'm not very good at operating GitHub

@maoyy maoyy added the bug label Sep 10, 2024
@maoyy maoyy closed this as completed Sep 10, 2024
@maoyy maoyy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 10, 2024
@maoyy maoyy closed this as completed Sep 10, 2024
@maoyy maoyy reopened this Sep 10, 2024
@stevemonaco
Copy link
Contributor

I can only repro when trying to adorn a Window (which may or may not be a supported use case). The adorner shows for any other case I've tried: a UserControl that creates + attaches the adorner to itself and creating+attaching the adorner to a child StackPanel.

Can you create a minimal repro and post the project?

@maoyy
Copy link
Author

maoyy commented Sep 12, 2024

I'm sorry

Because my custom panel is incorrect, the textbox is not displaying. I will study again. Thank you

@maoyy maoyy closed this as completed Sep 12, 2024
@maoyy
Copy link
Author

maoyy commented Sep 12, 2024

A new problem has been discovered.
The TestText Box control inherits from the Text Box and does not display when using it as a decorator. I have created a test project, thank you
test.zip

@maoyy maoyy reopened this Sep 12, 2024
@stevemonaco
Copy link
Contributor

@maoyy Hi, that file does not exist.

If you're inheriting a control, you need to ensure you provide a ControlTheme for it or use StyleKeyOverride so that it uses the ControlTheme of the parent. Otherwise, it has no visual.

@maoyy
Copy link
Author

maoyy commented Sep 13, 2024

Thank you
I uploaded the project, but I don't know why it hasn't.
I used StyleKeyOverride,I'll stick out the code。

test code:

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();

    var testPanel = new TestPanel();
    testPanel.Width = 600;
    testPanel.Height = 500;

    this.Content = testPanel;
}

}

public class TestPanel : Panel
{
public TestPanel()
{
Background = Brushes.Red;

    var testControl = new TestControl();
    testControl.Width = 200;
    testControl.Height = 200;

    this.Children.Add(testControl);
}

}

public class TestControl : Control
{
public TestControl()
{
this.PointerEntered += TestControl_PointerEntered;
}
public override void Render(DrawingContext context)
{
context.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Black, 1), new Rect(0, 0, Width, Height));
}
private void TestControl_PointerEntered(object? sender, Avalonia.Input.PointerEventArgs e)
{
var text = new TextBox();//TextBox
text.Text = "asdfasdfsdf";
text.PointerExited += Text_PointerExited;

    AdornerLayer.SetAdorner(this, text);
    AdornerLayer.SetIsClipEnabled(text, false);
}
private void Text_PointerExited(object? sender, Avalonia.Input.PointerEventArgs e)
{
    AdornerLayer.SetAdorner(this, null);
}

}

public class TestTextBox : TextBox
{
protected override Type StyleKeyOverride => base.StyleKeyOverride;
public TestTextBox() { }
}

thank you very much

@maoyy maoyy closed this as completed Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants