[英]Pagination or navigation control in Windows Phone 8.1 app
我正在开发Windows Phone 8.1应用
我已经在每个页面的顶部定义了导航路径。 但是随着路径的增加,尺寸不再适合我的屏幕。 目前,我正在寻找一个可以缩短路径的控件
请参考下图
任何帮助将不胜感激
谢谢
您可以编写自己的转换器,将字符串截断为给定的最大长度
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}}"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.