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

来源:互联网 发布:淘宝开店需要押金么 编辑:程序博客网 时间:2024/06/16 19:48
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;                }                            }        }    }


0 0
原创粉丝点击