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}}"/>