您的位置:首页 > 其它

经验及技巧:textblock 内容超出长度 文字向前移动一位

2015-03-19 14:16 357 查看
public class SafetyNumberPhoneViewModel : Screen
{
//实际存放 textblock的全部内容 包括看不见的部分
private string _phoneNumActual = "";

private string _phoneNun = "";

//PhoneNun前台 textblock 绑定的属性
public string PhoneNun
{
get
{
return _phoneNun;
}
set
{
_phoneNun = value;
NotifyOfPropertyChange("PhoneNun");
}
}
private INavigationService _navigationService;
public SafetyNumberPhoneViewModel(INavigationService navigationService)
{
_navigationService = navigationService;

}

public void OnClick(object source)
{
var _this = GetView() as SafetyNumberPhoneView;
//_this.TextPhoneNum
Button btn = source as Button;
string nun = btn.Content.ToString();
if (nun == "呼叫")
{
PhoneCallTask phoneTask = new PhoneCallTask();
phoneTask.PhoneNumber = _phoneNumActual;
phoneTask.Show();
}else if(btn.Content is Image)
{
int count = PhoneNun.Count();
int actual = _phoneNumActual.Count();

_phoneNumActual = _phoneNumActual.Substring(0, actual - 1);

if (actual>count)
{
actual = actual - 1;
PhoneNun = _phoneNumActual.Substring(actual - count, count);
}
else
{
PhoneNun = PhoneNun.Substring(0, count - 1);
}

}else
{
_phoneNumActual += nun;

double width = _this.TextPhoneNum.ActualWidth;
int count = PhoneNun.Count();
double charWidth = width / count;
if ((width + charWidth) > 450)
{
string temp = PhoneNun + nun;
PhoneNun = temp.Substring(1,temp.Length-1);
}
else
{
PhoneNun += nun;
}

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: