Ejemplo n.º 1
0
        private void UsernameHint_OnTap(object sender, GestureEventArgs e)
        {
            Caption.Focus();

            var frameworkElement = e.OriginalSource as FrameworkElement;

            if (frameworkElement != null)
            {
                var user = frameworkElement.DataContext as IUserName;
                if (user != null)
                {
                    var userBase = user as TLUserBase;

                    var index = 0;
                    for (var i = Caption.Text.Length - 1; i >= 0; i--)
                    {
                        if (Caption.Text[i] == '@')
                        {
                            index = i;
                            break;
                        }
                    }

                    if (TLString.IsNullOrEmpty(user.UserName))
                    {
                        if (userBase != null)
                        {
                            ViewModel.AddMention(userBase);

                            Caption.Text            = string.Format("{0}({1})", Caption.Text.Substring(0, index + 1), userBase.FullName);
                            Caption.SelectionStart  = Caption.Text.Length - userBase.FullName.Length - 1;
                            Caption.SelectionLength = userBase.FullName.Length;
                        }
                    }
                    else
                    {
                        Caption.Text            = string.Format("{0}{1} ", Caption.Text.Substring(0, index + 1), user.UserName);
                        Caption.SelectionStart  = Caption.Text.Length;
                        Caption.SelectionLength = 0;
                    }
                }
            }
        }