0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[.NetMaui]BindablePropertyの定義で躓いたところ

Last updated at Posted at 2025-02-28

背景

ContentViewを使って、CustomButtonというカスタムコントロールを作ろうとした

問題

カスタムコントロールに円を含めようとしたので、CustomRadiusという円の半径を表すプロパティを定義した。
その際double型のBindablePropertyをコードビハインドに定義したが、Exceptionエラーが出てアプリが落ちるようになった。

原因

初期値を80という整数にしていたことが原因だった。厳密に80.0など小数点を使って初期値を定義すれば解決した。

public static readonly BindableProperty CustomRadiusProperty =
    BindableProperty.Create(nameof(CustomRadius), typeof(double), typeof(CustomButton), 80.0, propertyChanged:OnCustomRadiusChanged);

public double CustomRadius
{
    get => (double)GetValue(CustomRadiusProperty);
    set => SetValue(CustomRadiusProperty, value);
}

static void OnCustomRadiusChanged (BindableObject bindable, object oldValue, object newValue)
{
    ~~
}
#endregion CustomRadius Property
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?