我希望這是簡單的東西,只是錯過了明顯的東西。我使用MVVM並且具有綁定到CollectionViewSource
這又填充了一個ObservableCollection
一個Datagrid
,在ObservableCollection
是initally無人居住,並加入到由勾選框的方式對UIWPF分組Datagrid行添加到集合時不可見
我的問題是,當ObservableCollection
被添加到,標題出現在DataGrid
上的分組中,但是單獨的行本身不包含。
任何幫助非常感激,
這是我的XAML爲DataGrid
<DataGrid DataContext="{Binding GroupedBookings}"
ItemsSource="{Binding SourceCollection}"
AutoGenerateColumns="False"
SelectionMode="Single"
SelectionUnit="FullRow"
CanUserSortColumns="True"
SelectedItem="{Binding SelectedBooking}"
CanUserAddRows="False">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=MemberCount.SupporterType}"
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=Name}" />
<TextBlock Text="{Binding Path=ItemCount}"
Margin="8 0 4 0" />
</StackPanel>
</Expander.Header>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Cost"
Binding="{Binding Cost}" />
<DataGridTextColumn Header="Order No"
Binding="{Binding LinkedOrderID}" />
</DataGrid.Columns>
</DataGrid>
和我的收藏
_bookings = new ObservableCollection<Booking>(rep.Bookings_Get().Where(x => x.JobID == CurrentJob.JobID));
GroupedBookings = CollectionViewSource.GetDefaultView(Bookings);
GroupedBookings.GroupDescriptions.Add(new PropertyGroupDescription("MemberCount.SupporterType"));
代碼,以確認觀察集合正在更新罰款是VM中的CollectionView
,頭中的ItemCount
甚至在UI中增加,我似乎無法使行顯示。
在此先感謝
編輯:
我已經改變了我的代碼直接分配給Bookings
而不是_bookings
按照EthicalLogics建議,但是這並沒有幫助Bookings
定義如下:
public ObservableCollection<Booking> Bookings
{
get { return _bookings; }
set
{
_bookings = value;
OnPropertyChanged("Bookings");
}
}
這裏是GroupedBookings
public ICollectionView GroupedBookings
{
get { return _groupedBookings; }
set
{
_groupedBookings = value;
OnPropertyChanged("GroupedBookings");
}
}
可以請你展示,你定義_bookings,因爲它似乎是一個字段中未從C#Codeing公約 – ethicallogics
私人的ObservableCollection _bookings財產;這是在我的虛擬機中定義的。謝謝 –
wisey
我已經排除它與itemsource的問題,如果我註釋掉Groupstyle xaml它更新正確,因此只能假設我的xaml在組風格中存在問題... – wisey