Reputation: 3019
i am developing windows phone 8.1 app
i have define navigation path on top of every page. but as my path grow, size does not fit my screen. currently i am searching a control to shorttern my path
please refer below image
Any help would be greatly appreciated
Thanks
Upvotes: 0
Views: 164
Reputation: 7301
You can write your own converter that truncates the string to a given maximal length
public class MaxStringConverter : IValueConverter
{
public MaxStringConverter()
{
ReplaceChars = "...";
MaxLenght = int.MaxValue;
}
public int MaxLength { get; set; }
public string ReplaceChars { get; set; }
public object Convert(object value, Type targetType, object parameter, string culture)
{
string val = (string)value;
int replaceCharLength = ReplaceChars.Length;
if(val.Lenght > MaxLength )
{
int middle = val.Lenght / 2;
int textLenth = MaxLength - 2 * replaceCharLength;
string textToReturn = val.Substring(middle - replaceCharLength , textLenth);
return string.Format("{1}{0}{1}", textToReturn, ReplaceChars);
}
}
}
Then use it as
<Window.Resources>
<MaxStringConverter x:Key="MaxStringConverter" MaxLength=100/>
</Window.Resources>
<TextBlock Text="{Binding Path=MyText, Converter={StaticResource MaxStringConverter}}"/>
Upvotes: 1