Replies: 2 comments 3 replies
-
...This is weird. I have subclassed my descendant from MaskedTextBox, and it started appearing. So, I am wondering what the trick is. |
Beta Was this translation helpful? Give feedback.
0 replies
-
While inheriting a control with a new control type, you also need to provide styles for this new control type. By default, Avalonia is not reusing styles from the base class. If you want to keep your new control type using TextBox styles, you should override StyleKeyOverride:
See https://docs.avaloniaui.net/docs/basics/user-interface/styling/styles#style-key |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In TextBox, the TextInput event does not work (TextBox consumes all characters without firing an event). I need to override this behavior, so I have created a simple descendant which overrides the OnTextInput method.
If I use TextBox directly (either in XAML or create one in code), it is shown in the view properly. As soon as I replace the name with the name of my descendant, the control is not shown (although, it is functional - I can type something and when I press Enter, which I also handle in the KeyDown event handler, it works). I checked whether MaskedTextBox (a descendant of TextBox) works when I replace the type of the created control, and it works. I don't see anything in MaskedTextBox that would make it visible where my control is not.
I thought about styles, but MaskedTextBox doesn't have styles too. Is it styled just because it is in the same namespace as TextBox itself?
In all cases, I specify only MinHeight and MinWidth. If I explicitly set Width and Height for my class, its border is shown, but there is no cursor there, and I cannot type in it (so, it must be just a border, not a control itself).
And then, how do I make my custom TextBox visible? Is it some kind of bug?
Beta Was this translation helpful? Give feedback.
All reactions