【发布时间】:2021-01-01 23:21:30
【问题描述】:
<CollectionView Grid.Row="2" Margin="25" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
SelectionMode="None" ItemsSource="{Binding Order}" x:Name="lstOrders">
<CollectionView.Header>
<Label Text="Siparişler" TextColor="Black" FontSize="18"/>
</CollectionView.Header>
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical" ItemSpacing="20"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<pv:PancakeView BackgroundColor="White" VerticalOptions="StartAndExpand"
HorizontalOptions="FillAndExpand">
<Grid VerticalOptions="StartAndExpand" HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<BoxView BackgroundColor="Red" WidthRequest="3" HorizontalOptions="Start"
VerticalOptions="FillAndExpand"/>
<Expander Grid.Column="1">
<Expander.Header>
<Grid HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="3.5*"/>
</Grid.ColumnDefinitions>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="{Binding OrderId}" TextColor="Black" FontSize="15"
HorizontalOptions="Center"/>
</StackLayout>
<BoxView Grid.Column="1" BackgroundColor="#F2F4F8" WidthRequest="1" HorizontalOptions="Start"
VerticalOptions="FillAndExpand"/>
<StackLayout Grid.Column="2" HorizontalOptions="Start" VerticalOptions="Center" Margin="20">
<Label Text="{Binding CompanyName}" TextColor="Black" FontSize="15"/>
<Label Text="{Binding Sum}" TextColor="#2F3246" FontSize="12" Margin="0,-10,0,0"/>
</StackLayout>
</Grid>
</Expander.Header>
<Grid HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="3.5*"/>
</Grid.ColumnDefinitions>
<BoxView Grid.Column="1" BackgroundColor="#F2F4F8" WidthRequest="1" HorizontalOptions="Start"
VerticalOptions="FillAndExpand"/>
<StackLayout Grid.Column="2" Spacing="10">
<Label Text="Ürünler" TextColor="Black" Opacity="0.5" FontSize="12" Margin="20,0" x:Name="txtId"/>
<StackLayout HorizontalOptions="Start" VerticalOptions="Center" Margin="20,0,0,20">
<Label TextColor="#2F3246" FontSize="12">
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="{Binding Count}"/>
<Span Text=" - "/>
<Span Text="{Binding Product}" FontAttributes="Bold"/>
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
<StackLayout HorizontalOptions="Start" VerticalOptions="Center" Margin="20,0,0,20">
<Label TextColor="#2F3246" FontSize="12">
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="{Binding Count1}"/>
<Span Text=" - "/>
<Span Text="{Binding Product1}" FontAttributes="Bold"/>
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
<StackLayout HorizontalOptions="Start" VerticalOptions="Center" Margin="20,0,0,20">
<Label TextColor="#2F3246" FontSize="12">
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="{Binding Count2}"/>
<Span Text=" - "/>
<Span Text="{Binding Product2}" FontAttributes="Bold"/>
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
<StackLayout HorizontalOptions="Start" VerticalOptions="Center" Margin="20,0,0,20">
<Label TextColor="#2F3246" FontSize="12">
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="{Binding Count3}"/>
<Span Text=" - "/>
<Span Text="{Binding Product3}" FontAttributes="Bold"/>
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
</StackLayout>
</Grid>
</Expander>
</Grid>
</pv:PancakeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
我想在集合视图中隐藏非文本位置,但不能在集合视图中使用 x:name。因此,如果跨度部分没有要写入的数据,我想隐藏我的跨度所在的堆栈布局。另外,根据我的任务,我不允许使用 MVVM。如何访问 Collectionview?你能帮帮我吗?
【问题讨论】:
-
你可以使用 StackLayout 的 IsVisible 。如果没有数据则设置为false。
-
我不能给出名称 stacklayout 因为 stacklayout 在列表视图中
-
你可以使用数据绑定。
-
为什么不尝试使用 LINQ 查询并选择唯一有名称的订单列表,然后将其传递到您的集合视图
-
更多细节,我是新人
标签: xamarin xamarin.forms xamarin.android monodevelop xamarin-studio