2017-09-14 4 views
1

XAML을 처음 접했을 때마다 루트보기 (StackLayout, ContentPage, ContentView, RelativeLayout 등)로 컨테이너를 사용하고 있습니다.Xamarin.Forms XAML 루트 요소로 이미지

그러나 이미지를 루트로 사용하는이 XAML을 실행합니다. 왜 우리가 그걸 할 것입니까?

<?xml version="1.0" encoding="utf-8" ?> 
<Image 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:r="clr-namespace:My.Resources;assembly=My.Resources" 
    x:Class="My.Views.Buttons.MyView" 
     Source="MyImage.png"/> 

나는 FFImageLoading.CachedImage이 이미지를 교체하고 싶지만 그것을 위해 나는 FFImageLoading의 XMLNS 네임 스페이스를 추가해야하지만 네임 스페이스는 외부 이미지 태그 안에없는 수 없기 때문에.

답변

1

루트 태그에 네임 스페이스를 지정하고 XAML의 루트 태그 자체에 사용할 수 있습니다. 예컨대 들어

:

<ffimageloading:CachedImage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="SomeAppNameSpace.CustomCachedImage" 
      Source="http://loremflickr.com/600/600/nature?filename=simple.jpg"> 
</ffimageloading:CachedImage> 

그냥 당신이 뒤에 코드에서 바로 클래스에서 파생 확인 : @SharadaGururay이 많은 감사

namespace SomeAppNameSpace 
{ 
    [XamlCompilation(XamlCompilationOptions.Compile)] 
    public partial class CustomCachedImage : CachedImage 
    { 
     public CustomCachedImage() 
     { 
      InitializeComponent(); 
     } 
    } 
} 
+1

:). 그것은 작동합니다. – pixel