【发布时间】:2015-04-23 06:05:47
【问题描述】:
我正在开发 windows phone 8.1 应用程序
我已经在每个页面的顶部定义了导航路径。但随着我的路径增长,尺寸不适合我的屏幕。目前我正在搜索一个控件来缩短我的路径
请参考下图
任何帮助将不胜感激
谢谢
【问题讨论】:
标签: c# visual-studio xaml windows-phone-8.1
我正在开发 windows phone 8.1 应用程序
我已经在每个页面的顶部定义了导航路径。但随着我的路径增长,尺寸不适合我的屏幕。目前我正在搜索一个控件来缩短我的路径
请参考下图
任何帮助将不胜感激
谢谢
【问题讨论】:
标签: c# visual-studio xaml 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}}"/>
【讨论】: