1 回答
TA贡献1946条经验 获得超3个赞
StackPanel 是此处使用的错误容器。您需要使用一个可以显示多个绑定数据项的容器。ItemsControl 是一个不错的选择,但请注意,它使用 ItemsSource 来获取数据,您需要将 DataContext 设置为高于该级别的级别。
<materialDesign:Card Background="{DynamicResource MaterialDesignBackground}">
<ItemsControl x:Name="spItemDisplay" ItemsSource="{Binding itemDisplayList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Expander x:Name="expander1" HorizontalAlignment="Stretch" Header="{Binding ItemName}">
<StackPanel Orientation="Vertical" TextBlock.Foreground="{DynamicResource MaterialDesignBody}" Margin="24,8,24,16">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label FontWeight="Bold" Content="Item Code" Grid.Column="0" Grid.Row="0" />
<TextBlock Text="{Binding ItemCode}" Grid.Column="1" Grid.Row="0"/>
<Label FontWeight="Bold" Content="Item Name" Grid.Column="0" Grid.Row="1" />
<TextBlock Text="{Binding ItemName}" Grid.Column="1" Grid.Row="1"/>
<Button Click="btnRemoveItem_Click" Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}" Width="30" Height="30" Padding="0" Background="{x:Null}" BorderBrush="{x:Null}">
<materialDesign:PackIcon Background="Transparent" Foreground="#FF3580BF" Kind="RemoveShoppingCart" Width=" 30" Height="30"/>
</Button>
</Grid>
</StackPanel>
</Expander>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</materialDesign:Card>
- 1 回答
- 0 关注
- 199 浏览
添加回答
举报