2016-09-21 49 views
0

我在xamarin.forms中使用usercontrol,並且需要訪問Content Page ContentView中使用的控件名稱。我想在按鈕點擊時對控件的可見性進行真/假。我正在獲取點擊事件,但需要訪問控件名稱以像標籤,條目。所有的如何訪問內容頁面中contentview所使用的控件名稱

+0

請顯示您訪問控件的代碼 –

+0

您應該在這裏進行一些改進,請參閱下面的答案! –

回答

0
  • 首先,如果你正在使用XAML PLC您應該創建ContentPage併爲你想上網,需要設定一個propertie名各控制。

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
        BackgroundColor="White" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
        x:Class="Gone.UsersXaml.ChatPage"> 
    
    <Label Text="Hello" x:Name = "MyLabel"/> 
    <Button x:Name = "MyButton"/> 
    </ContentPage> 
    
  • 然後在你的代碼背後是這樣......

    public partial class SignupPage : ContentPage 
    { 
        public SignupPage() 
        { 
         InitializeComponent(); 
         MyLabel.Text = "New Text Label"; 
         MyButton.IsVisible = true; 
        } 
    } 
    
1

您是否嘗試過使用?

Button myButton = [YourCONTENTVIEW].FindByName<Button>("myButton"); 
相關問題