Element adjacent to TextBox using AdornedElementPlaceholder - c#

I have a TextBox, I am trying to place a TextBlock adjacent to TextBox using AdornedElementPlaceholder when the TextBox has focus. But after reading from MSDN, I found that AdornedElementPlaceholder can only be used for ValidationError.
I have used a Grid with column, but this is tacking the actual TextBox width that I have set in XAML, I dont want to interfere the TextBox, just want to place a element next to it, irrespective of Width.
Adding a sample image, this image is part of Error Template I created for Validation. But I cant use ValidationTemplate here.
Please put light on this question.

Related

How to bring an element inside a list view item to the front of the entire app?

Using UWP XAML, I am trying to recreate this textbox UX from Postman whereby it pops up above all other elements in the app to display the full text: https://streamable.com/avrixo. I've almost fully recreated this UX, but I am having trouble bringing the textbox to the "front" of the app while the textbox is inside a listview.
What I have tried:
I have tried creating a UserControl for a custom text box with Canvas as its parent. Like this:
<Canvas>
<TextBox/>
</Canvas
I added some event handling to change the text wrapping and the Canvas.Zindex attached property of the textbox when the user focuses on it (I've tried setting the z-index to 1, 10, 100, and 1000000). However, I found that as the textbox expands vertically, it remains "behind" the listview item below it no matter what z-index I give it.
How can I bring the textbox inside a listview item to the "front" of the UI?
I don't think your problem is with z-index (per say) in this case. The problem here in the ListView is that each ListViewItem has it's own bounds, so the TextBox is being clipped by the bounding box of the item. You can double-check the bounding areas with the Visual Tree tools at least to confirm that's the issue.
If you don't want the ListViewItem to expand in size to match, I can see two options. When the user clicks to edit, you put a 'fake' TextBox (bound to the original in the ListView or the data item) either in 1) a Pop-up that you display or 2) in an overlay that's part of your page's XAML that has the textbox.
You can grab the selection state and cursor positions and such from the original textbox, and move focus to the new one and mirror that same state.
That's the approach I think I'd take.

WPF MultiLine TextTrimming

We have a case where we need to display Character Ellipsis(i.e. show text as trimmed) when we have multiline text.
The textblock shows trailing ellipsis when the content is anyway bigger than the width of the multiline TextBlock (i.e. TextWrapping is set to Wrap).
But we have a case wherein, we need to show only one line with ellipsis whether the text width of the first line is greater than the width of textblock or not.
For example, consider the following sample text
String str = "1\n2\n3456\n45889";
textBlock.Text = str;
The TextBlock should display as shown below:
1...
and the ToolTip will show the entire text. I tried doing some research on the possibilities but could not find much help and was wondering if anyone in the community has encountered such a situation or perhaps could suggest me?
Since, we shouldn't change the underlying data object (real time scenario) but only change what is rendered to the user, I am guessing a Converter should do the trick but I am still stuck on how to proceed. Or do you guys have any other alternatives?
Create a custom control based off of the textblock which handles the business logic needed for the ellipse.
The binding of the actual text to a specific property can ensure that the text is not changed. While in a separate property you have the visual text with the ellipse which gets updated when the original text changes (the dependency property change event) and the visual text subsequently displayed on the screen. Also have the tooltip bound to the original text which helps in that scenario of showing the actual text and not the ellipsed text.
By creating an easy custom control you have the ability to handle the business logic all in one location and it can be used in other screens and projects.

Scrolling all but the top line in a multiline textbox

I have a multiline textbox in a WinForms application. What I'd like to do is always have the top line visible, even if it scrolls. Is there some trick someone knows to do this?
Fake it. Use two TextBox objects, draw your own borders. You will need to deal with wrapping to the next line yourself.
You could also copy the first X characters to a label so when the TextBox scrolls they can see the first line in the label.
Unless it is an essential feature I would try to cut it.
The simple answer; depending on the appearance you are going for is to use existing windows controls to get the effect you want.
You can use a label control above a textbox and allow the textbox to scroll.
You can use two textbox - the top with it's .multiline property set to false, while the bottom allows scrolling.
You could encapsulate this all into a user control for reuseability.
Beyond that, I think you'd be looking at a fairly large project to implement your control (or at least overriding the onPaint() event of the textbox) with the desired behavior.

Auto position textblock

i'm currently trying to position my textblock in a way where it would automatically load below the next textblock after eg i click a button. (Its like a messenger , just that the text are set by me depending on events)
Other than scrollviewer to contain more textblock if it overshoot the screen, what do i need to make that work? or do i have to set a textblock there and hide it :(
I'm currently testing it out in sketch flow, would be nice if someone can tell me what to use to get this done or refer me somewhere relalted
Thank you!
Regards,
RAinbow
Use a StackPanel control to put the TextBlock controls in. It will stack the text blocks below one another.

WPF Textbox "normal" text input

G'day,
I'm not sure if this is a problem relevant to only me or if anyone else has this issue also. None the less, I'll try and describe what is going on here.
I have a few textbox's, default style, etc. I set an explicit maxwidth and maxheight to prevent resize when the text exceeds the default width of the textbox. The issue is that the text wraps to the next line, but I only want single line. So I set maxlines to 1 and textwrapping to NoWrap. That's fine.
Now the carat and typed text disappears under the edges of the textbox when the width is exceeded and the only way I can get the carat and newly typed text back into view is by pressing the left and right arrows. Coming from MFC and using textboxes all the time with HTML, I would have thought the default behaviour would be to have the textbox content scroll with the carat or am I missing something here?
Thank you,
Ash
What you are requesting is actually the default behavior. Start with an empty grid and place a textbox on it. Type some text into the box and the text view will scroll with the caret.
Below is the XAML I tested with, perhaps you have a style interfering with it?
<Grid>
<TextBox MaxWidth="20" Height="20"></TextBox>
</Grid>

Categories