【问题标题】:Hide frame in custom ContentView在自定义 ContentView 中隐藏框架
【发布时间】:2017-11-11 14:45:39
【问题描述】:

我在我的ListView 中使用名为CardViewTemplate.xaml 的内容视图页面来渲染具有两个帧的一些内容,其中一个应该是可见的,而另一个应该是不可见的。

        <ContentView xmlns="http://xamarin.com/schemas/2014/forms"
                     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        ...>
        <Frame  IsVisible="{Binding IsNotBreak}" IsClippedToBounds="True">
    .... content ....
        </Frame>
        <Frame IsVisible="{Binding IsBreak}" IsClippedToBounds="True">
    --content 2-
        </Frame>
      </ContentView>

上面的页面在列表视图中用于绑定和查看一些数据到列表视图,如下代码:

<ListView x:Name="listView" SelectedItem="{Binding SelcetedItem,Mode=TwoWay}" 
          RowHeight="-1" 
          ItemsSource="{Binding SelectedCard}" HasUnevenRows="True"   >
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Custom:CardViewTemplate/>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>

出乎意料的是,我的列表视图只显示了第二帧,并且看起来像附加图像:

【问题讨论】:

    标签: xaml xamarin.forms xamarin.forms.listview


    【解决方案1】:

    这是因为ContentView 应该只有一个孩子,而第二个Frame 覆盖了第一个Frame

    尝试添加一个类似AbsoluteLayoutGrid 的视图容器来将两个框架保存在ContentView 中:

    <ContentView xmlns="http://xamarin.com/schemas/2014/forms"
                     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        ...>
        <AbsoluteLayout>
    
            <Frame  IsVisible="{Binding IsNotBreak}" IsClippedToBounds="True">
        .... content ....
            </Frame>
            <Frame IsVisible="{Binding IsBreak}" IsClippedToBounds="True">
        --content 2-
            </Frame>
    
        </AbsoluteLayout>
    </ContentView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-06
      • 2015-10-14
      • 2016-11-05
      • 2013-02-10
      • 1970-01-01
      • 2021-06-04
      • 1970-01-01
      • 2015-03-21
      相关资源
      最近更新 更多