Уже несколько дней бьюсь с проблемой группировки данных. По примерам сделать не получается, либо группировка вообще не выводиться ни как, либо пишет что itemsSourse должен быть пуст перед записью. Помогите понять в чем проблема.
<Window x:Class="Buch.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Buch"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="1000">
<Window.Resources>
<CollectionViewSource x:Key="selectedClient" Source="{Binding SelectedClient.Purchases}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Date"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</Window.Resources>
<Grid x:Name="clientsList">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center" Margin="174,0">
<Button Content="Добавить" Margin="10" Command="{Binding AddCommand}"/>
<Button Content="Удалить" Margin="10" Command="{Binding DeleteCommand}"
CommandParameter="{Binding ElementName=clients, Path=SelectedItem}"/>
</StackPanel>
<ListBox Grid.Row="1" x:Name="clients" ItemsSource="{Binding Clients}" SelectedItem="{Binding SelectedClient}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock FontSize="24" Text="{Binding Name}"/>
<TextBlock FontSize="18" Text="{Binding Telephone}"/>
<TextBlock FontSize="18" Text="{Binding Balance}"/>
<TextBlock FontSize="18" Text="{Binding Address}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
<ListView Grid.Column="1" ItemsSource="{Binding SelectedClient.Purchases}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Date}">Дата</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Product.Type}">Тип товара</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Product.Material}">Материал</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Product.Size}">Размер</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Price}">Цена</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Count}">Количество</GridViewColumn>
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="True"
Background="#FF112255"
BorderBrush="#FF112255"
Foreground="#FFEEEEEE"
BorderThickness="1,1,1,5">
<Expander.Header>
<DockPanel>
<TextBlock FontWeight="Bold"
Text="{Binding Date}"
Margin="5,0,0,0"
Width="100"/>
</DockPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter/>
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</Grid>
public class Client : INotifyPropertyChanged
{
public int Id { get; set; }
private string name;
private string telephone;
private int balance;
private string address;
public ICollection<Purchase> Purchases { get; set; }
public string Address
{
get { return address; }
set
{
address = value;
OnPropertyChanged("Address");
}
}
public string Name
{
get { return name; }
set
{
name = value;
OnPropertyChanged("Name");
}
}
public string Telephone
{
get { return telephone; }
set
{
telephone = value;
OnPropertyChanged("Telephone");
}
}
public int Balance
{
get { return balance; }
set
{
balance = value;
OnPropertyChanged("Balance");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName]string prop = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
}
}
public class ClientVM : INotifyPropertyChanged
{
ApplicationContext db;
RelayCommand addCommand;
RelayCommand deleteCommand;
IEnumerable<Client> clients;
private Client selectedClient;
public Client SelectedClient
{
get { return selectedClient; }
set { selectedClient = value;
OnPropertyChanged("SelectedClient");
}
}
public IEnumerable<Client> Clients
{
get { return clients; }
set
{
clients = value;
OnPropertyChanged("Clients");
}
}
public ClientVM()
{
db = new ApplicationContext();
db.Clients.Load();
db.Purchases.Load();
db.Products.Load();
Clients = db.Clients.Local.ToBindingList();
}
public RelayCommand AddCommand
{
get
{
return addCommand ??
(addCommand = new RelayCommand((o) =>
{
ClientWindow clientWindow = new ClientWindow(new Client());
if (clientWindow.ShowDialog() == true)
{
Client client = clientWindow.Client;
db.Clients.Add(client);
db.SaveChanges();
}
}));
}
}
public RelayCommand DeleteCommand
{
get
{
return deleteCommand ??
(deleteCommand = new RelayCommand((selecterItem) =>
{
if (selecterItem == null) return;
Client client = selecterItem as Client;
db.Clients.Remove(client);
db.SaveChanges();
}));
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName]string prop = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
}
}
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Писал автообновляемое приложение на C#, проблема возникла в запуске уже обновленного приложения
У меня двигающаяся кнопка и 4 статичныеЭта двигающаяся кнопка не должна проходить сквозь другие
Добрый день! Есть TreeView, в нем есть кнопки, хочется сделать чтобы все эти кнопки был в одной колонки, друг под другом, как это можно сделать?...