【问题标题】:Xamarin - bind custom view contentXamarin - 绑定自定义视图内容
【发布时间】:2021-12-29 13:04:55
【问题描述】:

我创建了一个自定义视图,我想通过绑定来设置它的内容。这就是我所拥有的:

    <ContentView.Content>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="30"/>
            </Grid.ColumnDefinitions>

            <ffimageloadingsvg:SvgCachedImage Source="resource://CTP.SVG.exit.svg"
                                      Grid.Row="0" Grid.Column="1"
                                      HeightRequest="30" 
                                      WidthRequest="30"
                                      HorizontalOptions="Center"
                                      VerticalOptions="Center">
            </ffimageloadingsvg:SvgCachedImage>

            <redefinitions:BindableView Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" 
                                        Content="{Binding View, Source={x:Reference this}, Mode=OneWay}"/>

        </Grid>
    </ContentView.Content>

按照this 教程,我定义了我的 BindableView:

[ContentProperty(nameof(Content))]
public class BindableView : View
{
    public static readonly BindableProperty ContentProperty =
    BindableProperty.Create(
        propertyName: nameof(Content),
        returnType: typeof(View),
        declaringType: typeof(BindableView),
        defaultValue: default(View));

    public View Content
    {
        get { return (View)GetValue(ContentProperty); }
        set { SetValue(ContentProperty, value); }
    }
}

但 BindableView 永远不会显示,即使我静态定义了它的内容。 我错过了什么?

【问题讨论】:

    标签: xaml xamarin


    【解决方案1】:

    解决它的最简单方法是使用 ContentView 而不是自定义 BindableView

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多