Xaml中的命令是什么?如何使用它/查找引用?

Xaml中的命令是什么?如何使用它/查找引用?,xaml,Xaml,尝试实现此处描述的漂亮动画解决方案: 但当我剪切并粘贴此代码时: <?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="Animation.AnimationPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-nam

尝试实现此处描述的漂亮动画解决方案:

但当我剪切并粘贴此代码时:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="Animation.AnimationPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Animation" xmlns:views="clr-namespace:Animation.Views" 
BackgroundColor="#181818">
<Grid Padding="0" ColumnSpacing="0" RowSpacing="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="AUTO" />
    </Grid.RowDefinitions>

    <Image x:Name="MainImage" Grid.Row="0" Grid.RowSpan="2" Aspect="AspectFill" Source="mugello.jpg">
        <Image.GestureRecognizers>
            <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="Handle_Tapped" />
        </Image.GestureRecognizers>
    </Image>

    <views:ExpandBar x:Name="ExpandBar" Grid.Row="1" Padding="0" TranslationY="1" VerticalOptions="End" />

    <views:DescriptionPane x:Name="BottomFrame" Grid.Row="1" IsVisible="true" Text="The Mugello is a historic region and valley in northern Tuscany, in Italy. It is located to the north of the city of Florence and consists of the northernmost portion of the Metropolitan City of Florence.  It is connected to the separate Santerno river valley by the Futa Pass." VerticalOptions="End" />

    <views:Title x:Name="Title" Grid.Row="0" Margin="0,40,0,0" HorizontalOptions="Start" VerticalOptions="Start" />
</Grid>
最后,我在代码中出现了很多错误,比如“缺少程序集引用?”


这是搜索Google时特别困难的一件事,因为当你搜索时,只有用以下代码替换上面的代码,你才不会得到这些错误:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="Animation.AnimationPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Animation" xmlns:views="clr-namespace:Animation.Views" BackgroundColor="#181818">

<Grid Padding="0" ColumnSpacing="0" RowSpacing="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="AUTO" />
    </Grid.RowDefinitions>

    <Image x:Name="MainImage" Grid.Row="0" Grid.RowSpan="2" Aspect="AspectFill" Source="mugello.jpg">
        <Image.GestureRecognizers>
            <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="Handle_Tapped" />
        </Image.GestureRecognizers>
    </Image>

    <views:ExpandBar x:Name="ExpandBar" Grid.Row="1" Padding="0" TranslationY="1" VerticalOptions="End" />

    <views:DescriptionPane x:Name="BottomFrame" Grid.Row="1" IsVisible="true" Text="The Mugello is a historic region and valley in northern Tuscany, in Italy. It is located to the north of the city of Florence and consists of the northernmost portion of the Metropolitan City of Florence.  It is connected to the separate Santerno river valley by the Futa Pass." VerticalOptions="End" />

    <views:Title x:Name="Title" Grid.Row="0" Margin="0,40,0,0" HorizontalOptions="Start" VerticalOptions="Start" />
</Grid>
这是我从您提供的链接中找到的代码,当然有一个Contentpage,其中定义了名称空间。我不知道你为什么没有找到它

正如其他人已经告诉您的,这里的视图是一个名称空间。从

了解名称空间是什么好吧,这部分是名称空间的问题,但这并不是全部,为了让其他人遇到这种困惑,这里是完整的答案

首先,是的,名称空间是单词视图如何进入的,它位于文件开头的这一行:

xmlns:views="clr-namespace:Animation.Views"
…顺便说一句,只要您在同一页面上的其余命令中一致地使用单词views,它可以是任何内容。这基本上只是指向视图定义所在的路径

这是本文的另一部分,为了让它工作,必须有其他包含ContentView定义的Xaml文件。在clr名称空间之后的名称空间定义部分:必须指示在这些其他Xaml文件的代码后面声明的名称空间

而且,至关重要的是,这些其他文件没有显示在原始代码来源的博客文章中

有可能这一部分对经验丰富的人来说是显而易见的。但对我来说不是

因此,作为一个完整的示例,这里有一个Xaml文件,它将定义一个名为ContentDingle的视图:


所有其他答案都缺少的部分是对单独文件的解释,以及如何声明它们,以及如何引用它们。这可能也是noob的东西,但希望它能对其他noob有所帮助。

这是一个名称空间引用。了解XAML名称空间并检查xmlns:views=…好的,但名称空间内容不在代码本身中。你确定是这样的吗?像这样发布代码而不是发布命名空间定义是常见的吗?我真的不知道你说的对不对。当我搜索名称空间时,我发现了很多关于使用“x:”定义的东西,但这不是我要问的,我要问的是“视图:”语句。好吧,我看到了你认为链接引用了我的问题的地方,我看到了我的问题可能会使它看起来像这里唯一的问题是名称空间,但事实并非如此。这要简单得多,而且可能更像是一个noob问题。它只是在单独的文件中创建和引用ContentView。我在自己的回答中解释了更多。不过我对你的评论投了更高的票,因为我感谢你的帮助。我不知道为什么粘贴时顶部没有显示出来,但实际上它已经存在于文件中,我会出错。名称空间并不是真正的问题,尽管我明白为什么每个人都这么认为。我将编辑我的原始帖子以反映缺失的代码,这样人们就不会感到困惑。我比你高,因为我感谢你的帮助。
<?xml version="1.0" encoding="UTF-8"?>
<ContentView
    xmlns ="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="MyApp.ContentDingle">
    <Grid ColumnSpacing="0" RowSpacing="0">
        <Label 
            Text="I can now be referenced with the views command!"
            VerticalOptions="Center" />
    </Grid>
</ContentView>
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
    x:Class        ="MyApp.ContactDingleShowingPage"
    xmlns         ="http://xamarin.com/schemas/2014/forms"
    xmlns:x        ="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:views    ="clr-namespace:MyApp"
    BackgroundColor="#181818">
    <Grid>
        <views:ContentDingle/>
    </Grid>
</ContentPage>