如何解决WPF C#-DataGrid中的条件ItemSorce
我有下一个代码:
C#
public class CalculatedPointModel
{
public string PointId { get; set; }
public ObservableCollection<CalculatedBeamModel> CalculatedBeamsByPoint { get; set; }
public ObservableCollection<CalculatedPlanModel> CalculatedPlanByPoint { get; set; }
}
public class Data
{
public ObservableCollection<CalculatedPointModel> CalculatedPoints { get; private set; }
}
XAML
<Expander Grid.Row="0" Header="Results" Margin ="0,5">
<ItemsControl Grid.Row="0" Margin="25,10,10" ItemsSource="{Binding CalculatedPoints}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="0,10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock Text="{Binding PointId}"/>
</Border>
// ---------------------------------------------------------------------------------------------------------------------
<DataGrid Grid.Row="1" ItemsSource="{Binding CalculatedBeamsByPoint OR CalculatedPlanByPoint}" AutoGenerateColumns="False">
<DataGrid.Columns>
DataGridTextColumns depends on whether binding is CalculatedBeamsByPoint or CalculatedBeamsByPoint
</DataGrid.Columns>
</DataGrid>
// ---------------------------------------------------------------------------------------------------------------------
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Expander>
根据弯曲是CalculatedBeamsByPoint还是CalculatedPlanByPoint(其选择取决于类属性的值),将显示一个或另一个ObservableCollection的标题和数据。我该怎么做?我已经尝试过使用触发器和转换器,但是对我来说不起作用。
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。