【问题标题】:Windows phone Text BoundariesWindows 手机文本边界
【发布时间】:2015-02-16 13:27:49
【问题描述】:

我正在开始开发 Windows Phone 应用程序,但我不知道如何在文本块上获得矩形选择。 我正在寻找与 Android 中的 getTextBounds(...) 方法提供的完全相同的信息 (getTextBounds)

感谢您的帮助

【问题讨论】:

    标签: c# windows windows-phone-8 text bounds


    【解决方案1】:

    Windows Phone 8 没有任何直接测量文本的方法。最接近的方法是创建 TextBlock,然后检查其 ActualWidth。

    TextBlock t = new TextBlock();
    t.Text = "Lorum ipsum";
    
    Debug.WriteLine("Text {0} {1},{2}", t.Text, t.ActualWidth, t.ActualHeight);
    

    如果您更新到 Windows Phone 8.1,那么您可以与 DirectWrite 互操作以测量文本,但 DirectWrite 在 Windows Phone 8.0 上不可用。 Win2D 在the backlog 上有测量文本,但还没有(并且不支持 WP8)。

    【讨论】:

      【解决方案2】:

      你有没有偶然询问focusingTextbox

      //For your textbox
      private void yourTextBox_GotFocus(object sender, RoutedEventArgs e)
      {
        (sender as TextBox).Text = string.Empty;
      }
      

      Reference

      或者尝试使用Control.Focus

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 2023-04-07
      • 2012-11-21
      • 1970-01-01
      相关资源
      最近更新 更多