속성이있는 사용자 지정 컨트롤을 만들어야합니다.속성이있는 사용자 지정 컨트롤을 만드는 방법
이 내 사용자 정의 컨트롤입니다 :
public class ExpandableStackLayout : StackLayout
{
public String Title{get;set;}
public ContentView View { set; get; }
public String Image{set;get;}
public ExpandableStackLayout(string title, string image, ContentView view)
{
Title = title;
Image = image;
View = view;
}
}
하지만 XAML에서 그것을 사용하려고 할 때 말한다 : "없음 기본 생성자를 찾을 수 없습니다"그리고 난이 기본 생성자 호출을 작성하지 않을 경우 매개 변수와 함께 생성자를 호출합니다.
이
내 XAML입니다 :<control:ExpandableStackLayout Title="Title" Image="imag.png">
<control:ExpandableStackLayout.View>
<ContentView>
<OtherView/>
</ContentView>
</control:ExpandableStackLayout.View>
</control:ExpandableStackLayout>
UPDATE 나는 당신의 팁을 시도
와 나는 다른 사람의 문제가 : 생성자를 만들 필요가
public static readonly BindableProperty TitleProperty = BindableProperty.Create(
propertyName: "Title",
returnType: typeof(String),
declaringType: typeof(String),
defaultValue: String.Empty);
public String Title
{
get => (String)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
public ContentView View { set; get; }
public static readonly BindableProperty ImageProperty = BindableProperty.Create(
propertyName: "Image",
returnType: typeof(String),
declaringType: typeof(String),
defaultValue: string.Empty);
public String Image
{
get => (String)GetValue(TitleProperty);
set => SetValue(ImageProperty, value);
}
public ExpandableStackLayout()
{
//Do somethings whith parameters but are null
usemyParameters();
}
declaringType은 'typeof (ExpandableStackLayout)'여야합니다. –
속성의 유형 ?? 어디에 넣었는지 보여 줄 수 있습니까? –
물론'공공 정적 읽기 전용 BindableProperty ImageProperty = BindableProperty.Create ( propertyName 형식 : "이미지", returnType이 : 대해서 typeof (문자열), declaringType : 대해서 typeof (ExpandableStackLayout), DEFAULTVALUE : String.Empty로)'. [here] (https://developer.xamarin.com/guides/xamarin-forms/xaml/bindable-properties/)에 대한 자세한 내용을 볼 수 있습니다. –