c# - Changing text truncation behavior -


i want display path in textblock.

standard truncation ends removing relevant parts of information want show, since truncates rightmost part of line first.

is there way specify, in xaml, text should truncated left first rather right? setting flowdirection , textreadingorder doesn't seem have effect on direction of truncation, seen below:

<textblock text="{binding path}" fontsize="18" flowdirection="righttoleft" textreadingorder="useflowdirection" texttrimming="characterellipsis" /> 

is possible in pure xaml, or solution need more complex (examining size of textblock on page resize , modifying text compensate)?

i think want trim text left when text long? if so, there no such property can set work in uwp, need trim yourself.

here demo:

<textblock text="left-abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz            abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz            abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz            abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz            abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz-right"            margin="0,5" textwrapping="nowrap"            loaded="textblock_loaded" /> 

code behind:

private void textblock_loaded(object sender, routedeventargs e) {     var tb = sender textblock;     //desired width of textblock     var desiredwidth = tb.desiredsize.width;     //cal. char. in string     var count = tb.text.count();     var reducedtext = tb.text;     if (reducedtext != "")     {         //actual width of text         var textwidth = tb.actualwidth;         //trim count         var trimcount = math.ceiling((count / textwidth) * desiredwidth) - 4;         reducedtext = "... " + reducedtext.substring((int)(count - trimcount), (int)trimcount);         tb.text = reducedtext;     } } 

my demo consider scenario text long (actualwidth > desiredwidth), implement scenario if size enough hold text. , careful method works in loaded event since actualwidth changed rendered width instead of text-width textblock rendered completely.

also, since you're using data binding text property of textblock, may create converter trim text.


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -