我有下面的代码我的页面XAML:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:effects="clr-namespace:Coodo.Effects;assembly=Coodo"
x:Class="Coodo.Pages.MessagePage">
<effects:ContainerWithShadow>
<Label Text="123" />
</effects:ContainerWithShadow>
</ContentPage>和用于存储视图的ContainerWithShadow类
using Xamarin.Forms;
namespace Coodo.Effects
{
[ContentProperty("ContainerContent")]
public class ContainerWithShadow : ContentView
{
public View ContainerContent { get; set; }
}
}但我的标签XAML没有绑定到ContainerWithShadow.ContainerContent。如果设置断点,代码不会停止在setter上。
发布于 2018-06-19 11:50:36
ContainerContent属性必须是BindableProperty.需要更改以下代码:
[ContentProperty("Conditions"), Preserve(AllMembers = true)]
public class ContainerWithShadow : ContentView
{
public static readonly BindableProperty StateProperty = BindableProperty.Create(nameof(ContainerWithShadowChild), typeof(object), typeof(View), propertyChanged:PropertyChanged);
private static void PropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
{
}
public View ContainerWithShadowChild
{
get => (View)GetValue(StateProperty);
set => SetValue(StateProperty, value);
}
}代码就能正常工作。
https://stackoverflow.com/questions/50927289
复制相似问题