2016-09-21 51 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"); 
相关问题