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;
}
}
}
}
经验及技巧:textblock 内容超出长度 文字向前移动一位
最新推荐文章于 2020-12-07 09:28:39 发布