代码之家  ›  专栏  ›  技术社区  ›  Snake Eyes

xamarin 3.3.0表单错误:在xmlns中找不到类型toolbaritem

  •  1
  • Snake Eyes  · 技术社区  · 6 年前

    我有:

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="{Binding [AddPhoto]}" Command="{Binding AddNewPhotoCommand}" Order="Primary" x:TypeArguments="FileImageSource" Icon="{OnPlatform iOS='photo.png', UWP='Assets/photo.png'}"/>
    </ContentPage.ToolbarItems>
    

    我得到了:

    在xmlns中找不到类型toolbaritem http://xamarin.com/schemas/2014/forms

    如果我在 x:TypeArguments="FileImageSource" 意思是

     <ToolbarItem Text="{Binding [AddPhoto]}" Command="{Binding AddNewPhotoCommand}" Order="Primary"/>
    

    那就好了,没有错误。

    我将项目升级到Xamarin 3.3.0,并从

    <ToolbarItem Text="{Binding [AddPhoto]}" Command="{Binding AddNewPhotoCommand}" Order="Primary" >
          <ToolbarItem.Icon>
            <OnPlatform x:TypeArguments="FileImageSource">
              <On Platform="iOS" Value="photo.png"/>
              <On Platform="UWP" Value="Assets/photo.png"/>
            </OnPlatform>
          </ToolbarItem.Icon>
    </ToolbarItem>
    

    <ToolbarItem Text="{Binding [AddPhoto]}" Command="{Binding AddNewPhotoCommand}" Order="Primary" x:TypeArguments="FileImageSource" Icon="{OnPlatform iOS='photo.png', UWP='Assets/photo.png'}"/>
    

    为什么?

    我没有打字错误之类的。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Access Denied    6 年前

    Check out 使用方法:

    <ContentPage Title="Browse">
            <ContentPage.Icon>
                <OnPlatform x:TypeArguments="FileImageSource">
                    <On Platform="iOS">tab_feed.png</On>
                    <On Platform="Android>tab_feedand.png</On>
                    <On Platform="UWP>/Images/tab_feed.png</On>
                </OnPlatform>
            </ContentPage.Icon>
        </ContentPage>
    

    将成为:

    <ContentPage Title="Browse" Icon="{x:OnPlatform iOS='tab_afeed.png', Android='tab_feedand.png', UWP='/Images/tab_feed.png' />
    

    不需要指定x:typearguments。

    x:typeArguments 将泛型的约束类型参数传递给泛型类型的构造函数。所以它与 OnPlatform 方法,但要为ToolbarItem指定它。