0

这是我需要解决的问题。

我的数据内容在 DemoList 类中:

注意:DemoHeader 对象包含 DemoItem 对象的 ObservableCollection,DemoList 对象包含 DemoHeader 对象的 ObservableCollection

public enum Type { article, product, material }

public class DemoHeader
{
    private ObservableCollection<DemoItem> _items;

    public ObservableCollection<DemoItem> Items
    {
        get { return _items; }
        set { _items = value; }
    }

    public DemoHeader(string document)
    {
        this._salesOrder = document;
        _items = new ObservableCollection<DemoItem>();
    }

    private string _salesOrder;

    public string SalesOrder
    {
        get { return _salesOrder; }
        set { _salesOrder = value; }
    }
}

public class DemoItem
{
    public DemoItem(string name, Type type)
    {
        this._name = name;
        this._type = type;
    }

    private Type _type;

    public Type Type
    {
        get { return _type; }
        set { _type = value; }
    }

    private string _name;

    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
}


public class DemoList : ObservableCollection<DemoHeader>//, ICollectionView
{
    public DemoList() 
    {
        DemoHeader dd = new DemoHeader("Doc-1");
        dd.Items.Add(new DemoItem("T-1", Type.article));
        dd.Items.Add(new DemoItem("M-1", Type.material));

        DemoHeader dd2 = new DemoHeader("Doc-2");
        dd2.Items.Add(new DemoItem("P-1", Type.product));
        dd2.Items.Add(new DemoItem("P-2", Type.product));

        this.Add(dd);
        this.Add(dd2);

    }
}

XAML:

注意:每个 ListBox 都有 4 个 CollectionViewSource。

<Window x:Class="WuZet.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:c="clr-namespace:WuZet"
        Title="WuZet" WindowStartupLocation="CenterScreen" ResizeMode="CanResize" Loaded="window_loaded" Background="#ECE9D8" WindowStyle="ToolWindow" Icon="/WuZet;component/Images/ksi_ikona.ico" Topmost="True" WindowState="Maximized" SizeToContent="WidthAndHeight"> 
    <Window.Resources>
        <CollectionViewSource x:Key="list" Source="{Binding}"></CollectionViewSource>
        <CollectionViewSource x:Key="wares" Source="{Binding Source={StaticResource list}, Path=Items}" Filter="wareFilter"></CollectionViewSource>
        <CollectionViewSource x:Key="materials" Source="{Binding Source={StaticResource list}, Path=Items}" Filter="materialFilter"></CollectionViewSource>
        <CollectionViewSource x:Key="products" Source="{Binding Source={StaticResource list}, Path=Items}" Filter="productFilter"></CollectionViewSource>
    </Window.Resources>    
    <Grid>
        <Grid.RowDefinitions> 
            <RowDefinition Height="80"></RowDefinition>
            <RowDefinition Height="20"></RowDefinition>
            <RowDefinition Height="200"></RowDefinition>
            <RowDefinition Height="50"></RowDefinition>
            <RowDefinition Height="200"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <StackPanel Grid.Row="0" Grid.ColumnSpan="2" Margin="5,5,5,5">
            <TextBox/>
            <Button Content="ok" Margin="0,5,0,0" HorizontalAlignment="Stretch" Height="30"  Width="150" Click="Button_Click"/>
        </StackPanel>

        <StackPanel Grid.RowSpan="2" Grid.Column="2">
            <ListBox Name="orders" IsEnabled="{Binding ElementName=check, Path=IsChecked}" Margin="85,5,85,5" Height="70" ItemsSource="{Binding Source={StaticResource list}}" DisplayMemberPath="SalesOrder"/>
            <CheckBox Name="check" HorizontalAlignment="Center" Content="Wybierz zamówienie" IsChecked="False"/>
        </StackPanel>

        <GroupBox Header="Wares" Grid.Row="2" Grid.Column="0">
            <ListBox Name="lbWares" ItemsSource="{Binding Source={StaticResource wares}}" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <!--<StackPanel Orientation="Horizontal">-->
                        <TextBlock Text="{Binding Path=Name}"></TextBlock>
                            <!--<TextBlock Text="{Binding ZaE_TwrKod}" />
                            <TextBlock Text=", " />
                            <TextBlock Text="{Binding ZaE_Ilosc}" />
                            <TextBlock Text=", " />
                            <TextBlock Text="{Binding ZaE_TwrNazwa}" />-->
                        <!--</StackPanel>-->
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </GroupBox>

        <GroupBox Header="Materials" Grid.Row="2" Grid.Column="1">
            <ListBox Name="lbMaterials" ItemsSource="{Binding Source={StaticResource materials}}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <!--<StackPanel Orientation="Horizontal">-->
                            <TextBlock Text="{Binding Path=Name}"/>
                            <!--<TextBlock Text=", " />
                            <TextBlock Text="{Binding ZaE_Ilosc}" />
                            <TextBlock Text=", " />
                            <TextBlock Text="{Binding ZaE_TwrNazwa}" />-->
                        <!--</StackPanel>-->
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </GroupBox>

        <GroupBox Header="Products" Grid.Row="2" Grid.Column="2">
            <ListBox Name="lbProducts" ItemsSource="{Binding Source={StaticResource products}}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <!--<StackPanel Orientation="Horizontal">-->
                            <TextBlock Text="{Binding Path=Name}"/>
                            <!--<TextBlock Text=", " />
                            <TextBlock Text="{Binding ZaE_Ilosc}" />
                            <TextBlock Text=", " />
                            <TextBlock Text="{Binding ZaE_TwrNazwa}" />
                        </StackPanel>-->
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </GroupBox>
</Window>

DemoList 对象绑定到 CollectionViewList x:Key=list

这是我需要实现的业务逻辑:

  • 如果复选框被标记,我需要将选定的 ListBoxItem 返回到相应的容器 [商品、产品、材料] - 这个逻辑是有效的
  • 如果未选中复选框,我需要将
    所有标题的所有项目 [ObservableCollection] 返回到相应的容器 [商品、产品、材料]

我被困在这里,谁能给我一个解决方案?

--- 2013-11-04 20:38

为误解和我糟糕的英语道歉。

我上传了一些屏幕以更清晰。

http://imgur.com/UowQrRP

正如您在屏幕上看到的,我需要为复选框实现行为。取消选中时,每个 DemoItem 对象必须显示在 3 个容器之一中。每个容器都绑定到 CollectionViewSource。

4

0 回答 0