0
我正在开发windows phone 8.1应用程序Windows Phone 8.1中的分页或导航控件应用程序
我已经在每个页面的顶部定义了导航路径。但随着我的发展,尺寸不适合我的屏幕。目前我正在寻找一个控制shorttern我的路
请参考下面的图片
任何帮助,将不胜感激
感谢
我正在开发windows phone 8.1应用程序Windows Phone 8.1中的分页或导航控件应用程序
我已经在每个页面的顶部定义了导航路径。但随着我的发展,尺寸不适合我的屏幕。目前我正在寻找一个控制shorttern我的路
请参考下面的图片
任何帮助,将不胜感激
感谢
您可以编写自己的转换器,截断给定最大长度的字符串
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);
}
}
}
然后用它作为
<Window.Resources>
<MaxStringConverter x:Key="MaxStringConverter" MaxLength=100/>
</Window.Resources>
<TextBlock Text="{Binding Path=MyText, Converter={StaticResource MaxStringConverter}}"/>