Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml Can';无法从xamarin forms项目的pcl部分的代码隐藏中访问控件_Xaml_Xamarin_Xamarin.forms_Code Behind_Xforms - Fatal编程技术网

Xaml Can';无法从xamarin forms项目的pcl部分的代码隐藏中访问控件

Xaml Can';无法从xamarin forms项目的pcl部分的代码隐藏中访问控件,xaml,xamarin,xamarin.forms,code-behind,xforms,Xaml,Xamarin,Xamarin.forms,Code Behind,Xforms,我有一个包含pcl部分和本机win、ios和android部分的Xamarin.Forms项目。 所有页面结构和视图模型都在pcl部分。应用程序工作很好,但当我试图隐藏网格以防代码隐藏时,它什么也不做。下面是代码示例: Xaml: <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Cla

我有一个包含pcl部分和本机win、ios和android部分的Xamarin.Forms项目。 所有页面结构和视图模型都在pcl部分。应用程序工作很好,但当我试图隐藏网格以防代码隐藏时,它什么也不做。下面是代码示例:

Xaml

<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="SomeNamespase.SomePage">

    <Grid x:Name="InnerGrid" BackgroundColor="Green">
        <Frame x:Name="InnerContent"/>
    </Grid>
</ContentPage>
我也尝试过
这个.FindByName(“InnerGrid”)相同的结果


注意:如果我试图从PCL中的操作获取控件,那么一切都很好。当我试图在windows(或其他平台)项目中从ViewPresenter获取控件时,没有发生任何事情。

您需要确保正确实现INotifyPropertyChanged

protected virtual void OnPropertyChanged(string propertyName)
{
    if (PropertyChanged != null)
    {
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

请尝试下面的代码,因为在你的代码中我看不到构造函数

using System;

namespace SomeNamespase
{
    public partial class SomePage : ContentPage
    {
        public SomePage() 
       {
            SomeMethod() ;
       } 
        public void SomeMethod()
        {
            this.InnerGrid.IsVisible = false;
            this.InnerContent.BackgroundColor = Color.Aqua;           
        }
    }
} 

您是否尝试过将网格的可见性绑定到ViewModel中的属性?是的,当然也没有帮助。如果您设置了断点,代码行是否正在执行?是的,在调试模式下,代码正在所有行中运行,但没有任何问题。对于不完整的代码示例,构造函数在那里。但当我们使用一种接口实现的方法时,方法不应该在构造函数中使用,而应该在运行时使用
using System;

namespace SomeNamespase
{
    public partial class SomePage : ContentPage
    {
        public SomePage() 
       {
            SomeMethod() ;
       } 
        public void SomeMethod()
        {
            this.InnerGrid.IsVisible = false;
            this.InnerContent.BackgroundColor = Color.Aqua;           
        }
    }
}