0
我試圖用WPF數據網格中的類列表來顯示一個類。嵌套集合添加問題
我有以下XAML:
<Window x:Class="Main.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
FlowDirection="RightToLeft">
<Grid>
<DataGrid Height="auto" Width="auto" Name="DaveningTimes" CanUserAddRows="False" AutoGenerateColumns="False">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Padding="3"/>
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander>
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=ItemCount}" Margin="8,0,4,0"/>
<TextBlock Text="{Binding Path=Name}" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding Alerts}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding AlertTime.time, ValidatesOnExceptions=True, Mode=TwoWay}" Header="זמן" Width="auto"/>
<DataGridTemplateColumn Header="קובץ התראה" MinWidth="300">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<TextBox Text="{Binding AlertProgram, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsEnabled="False" Grid.Column="0" x:Name="PathToFile"/>
<Button Content="..." Grid.Column="1" Click="Button_browse_alert_program" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding DaveningTime}" Header="זמן תפילה" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding DaveningName}" Header="סוג תפילה" IsReadOnly="True"/>
<DataGridCheckBoxColumn Binding="{Binding ToAlert}" Header="להתריע?" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
的背後代碼:
IList<Davening> prayes;
public ICollectionView prayes_view { get; private set; }
public MainWindow()
{
prayes = getPrayers(getHTMLfromURL()).ToList();
InitializeComponent();
prayes_view = new ListCollectionView(prayes.ToList());
prayes_view.GroupDescriptions.Add(new PropertyGroupDescription("DaveningName"));
prayes_view.CollectionChanged += prayes_view_CollectionChanged;
DaveningTimes.ItemsSource = prayes_view;
}
凡getPrayers(getHTMLfromURL())
從互聯網上獲取我顯示的數據。
我用下圖中描述的類:
問題:
通過在數據網格這是該行的細節增加了項目在用戶添加列,但所有的值都是null
。另外,驗證似乎不起作用(沒有紅色標記或任何類似的東西)
感謝您的建議,但這並沒有回答這個問題。如果您可以在評論中鏈接關於這個主題的幾篇文章... – elyashiv