2017-09-22 5 views
0

私はwrappanel.but用のカスタムコントロールを作成しました。余分なスペースがあります。 私はコントロールのHeightRequestのBindablePropertyを作成し、余分なスペースを削除するためにコンテンツに応じて設定しようとしています。カスタムxamarin.formsのカスタムコントロールのHeightRequestのBindableProperty

これは私がHeightRequest

のBindablePropertyに
public double HeightRequest { get; set; } 

    private static BindableProperty heightTextProperty = BindableProperty.Create(
                propertyName: "HeightRequest", 
                returnType: typeof(double), 
                declaringType: typeof(InstallationPhotoWrappanel), 
                defaultValue: 100, 
                defaultBindingMode: BindingMode.TwoWay, 
                propertyChanged: heightTextPropertyChanged); 

    private static void heightTextPropertyChanged(BindableObject bindable, object oldValue, object newValue) 
    { 
     var control = (InstallationPhotoWrappanel)bindable; 
     control.HeightRequest = Convert.ToDouble(newValue); 
    } 

を作成する方法であるが、それは私が間違っhere.pleaseヘルプをやって何

exception has been thrown by the target of an invocation 

私に例外を提供します。

ありがとうございます。

答えて

1

カスタムコントロールは、すでにHeightRequest性質を持っている必要があります。私はHeightTextという名前のカスタムバインド可能なプロパティを作成していると仮定しています。

それがそうであるならば、私はコード内で見ることができる3つの問題があります。

  1. propertyName: "HeightRequest"することは、我々がターゲットプロパティの型の不一致の例外を取得しないようにするにはpropertyName: "HeightText"

  2. する必要があり、 defaultValue: (double)100

  3. defaultValue: 100を変更し、GetValueを使用してHeightTextプロパティを追加し、SetValue

    public double HeightText 
    { 
        get 
        { 
         return (double)GetValue(HeightTextProperty); 
        } 
        set 
        { 
         SetValue(HeightTextProperty, value); 
        } 
    } 
    
0

コードを見て試してみてください。希望、それはあなたを助けるでしょう。

コード

public static readonly BindableProperty HeightRequestProperty = 
    BindableProperty.Create<InstallationPhotoWrappanel,double>(i=>i.HeightRequest,100,BindingMode.TwoWay,heightTextPropertyChanged); 

public double HeightRequest 
{ 
    get 
    { 
     return (double)GetValue(HeightRequestProperty); 
    } 
    set 
    { 
     SetValue(HeightRequestProperty, value); 
    } 
} 

static bool heightTextPropertyChanged(BindableObject bindable, double value) 
{ 
    var control = (InstallationPhotoWrappanel)bindable; 
    control.HeightRequest = value; 
    return true; 
} 
関連する問題