c# - Find the width/right coordinates of a TextBlock with dynamic text in WPF -
i want have textblock user's name , right @ end of string, image click , edit name.
since can't control name's length , want follow input string last character, need figure width or right border point of text block.
i've tried width (nan) , actualwidth (always 0) after setting text property, didn't work (tried updatelayout() well).
the text left aligned element can't right-align it.
how can position of right part of textblock dynamically input text in either code or xaml?
you can use actualwidth property width of textblock. right after setting text, actualwidth not updated immediately. 1 solution listen changes on actualwidth of textblock, , right value whenever it's changed
public mainwindow() { initializecomponent(); dependencypropertydescriptor.fromproperty(textblock.actualwidthproperty, typeof(textblock)) .addvaluechanged(textblock1, (s, e) => { var yourexpecedwidth = textblock1.actualwidth; }); }
Comments
Post a Comment