2017-07-04 80 views
1

即時通訊xamarin.forms相當新。我已經開始創建一個應用程序,它將顯示從書中檢索到的大量文本。目前,我將文本添加到標籤中,但用戶無法在三個平臺中的任何一個平臺上覆制他在屏幕上看到的文本?有沒有辦法從xamarin.forms中的標籤複製文本?我也試過編輯器,它可以在推入編輯器時複製數據,但是用戶可以輸入字符,這是我不希望他們做的。我只想顯示我從流中讀取的文本,並使用戶可以複製他希望的文本數量。任何幫助將不勝感激!從xamarin.forms中的標籤複製文本

+0

你可以使用一個按鈕,或手勢添加到標籤,將複製標籤文本到剪貼板。 – Jason

+0

您可以編輯子類並覆蓋文本更改的事件,以防止用戶更改文本。 – Slepz

+0

嘗試創建渲染器並使其只讀 – Krishna

回答

1

你能低於

嘗試Page.Xaml

<Entry TextChanged="Handle_TextChanged" Text="EnteyText" Unfocused="Handle_Unfocused" Focused="Handle_Focused" x:Name="entry" HeightRequest="50" WidthRequest="100" BackgroundColor="Aqua"/> 
<Button Text="Bind Text From Book" Clicked="Handle_Clicked" HeightRequest="50" WidthRequest="100" /> 

Page.Xaml.CS

bool isFocused; 
    string entryText="EnteyText"; 

    void Handle_Focused(object sender, Xamarin.Forms.FocusEventArgs e) 
    { 
     isFocused = e.IsFocused; 
    } 

     void Handle_Unfocused(object sender, Xamarin.Forms.FocusEventArgs e) 
     { 
      isFocused = e.IsFocused; 
     } 

     void Handle_TextChanged(object sender, Xamarin.Forms.TextChangedEventArgs e) 
     { 
      if (!isFocused) 
      { 
       entryText = (sender as Entry).Text; 
      } 
      if (isFocused && entryText != e.NewTextValue) 
      { 
       (sender as Entry).Text = e.OldTextValue; 
      } 
     } 

     void Handle_Clicked(object sender, System.EventArgs e) 
     { 
      entry.Unfocus(); 
      entry.Text = "Text from book"; 
     }