質問

私はその2つの列がコンボボックスであることがDataGridを持っています(これは問題はほとんど含まれていません)。

私は、ユーザーが最初のコンボの値を変更すると、他の列のコンボボックスはそのプロパティにバインドする必要があります(このプロパティはコレクションです)。最初のComboBoxはカテゴリであると言う、ユーザーがその値を変更するときに、他のCBに(最初のコンボの選択されたカテゴリ).vendorsの値が入力されます。

どうすればよいです、私はMVVMを使わない、単純なWPFだけです。 私はそれを実装する正しい方法であるべきことがわからない、私はそれを正しく始めたことを願っています。

最初のCombobox(別のDataGridCellにある)を最初のSelectionChangeHandlerから入手できれば、最初の選択変更の変更に応じて、そのソースをリセットできます。 現在の(最初の)DataGridCellに到達する機能があることに注意してください。私はちょうど正しいDataGridCell兄弟にアクセスするための効率的な方法を探していて、その子供(2番目の)コンボを取得します。

選択したカテゴリは行ごとに異なり、2番目のコンボボックスはこの行のカテゴリに依存する必要があります。
CollectionViewSource.Sourceが現在のアイテムにバインドされるように実際に実装しようとしました(すなわち、行のDataContext)が機能しないようです。
私は、第1のコンボボックスのSelectionChangeでアクショントリガーまたはハンドラを2番目に設定するのを好みます。

その分野の他のコンボボックスは、すべて互いに縛られているので問題を生じさせないようです、とにかくCollectionViewSource.filterを使用することはできません。別のDatagridcellの深さにある離れたいとこである最初のもの。

これまでに試したものは何ですか:

<DataGrid>
    <DataGrid.Resources>
        <CollectionViewSource x:Key="CategoriesCollection" Source="{Binding Context.CategoriesList, Source={x:Static Application.Current}, IsAsync=True}" />
    </DataGrid.Resources>

    <DataGrid.Columns>

        <DataGridTemplateColumn Header="Category">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock DataContext="{Binding Category}" Text="{Binding Title}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
            <DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <!--This is the first ComboBox-->
                    <ComboBox
                                IsSynchronizedWithCurrentItem="False"
                                ItemsSource="{Binding Source={StaticResource CategoriesCollection}}"
                                DisplayMemberPath="Title"
                                SelectionChanged="cbCategories_SelectionChanged"
                                SelectedItem="{Binding Category}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellEditingTemplate>
        </DataGridTemplateColumn>

        <DataGridTemplateColumn Header="Style">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock DataContext="{Binding Finish.Style.Vendor}" Text="{Binding Contact.Title}"/>
                        <TextBlock DataContext="{Binding Finish.Style}" Text="{Binding Title}"/>
                        <TextBlock Text="{Binding Finish.Title}"/>
                    </StackPanel>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
            <DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <StackPanel>
                        <StackPanel.Resources>
                            <!--I want, that when the user selects a value in the first ComboBox,
                    the VendorsCollection below should be populated with the selected Category.Vendors,
                    or alternatively current row's data item.Category.Vendors,
                    I just donno how to access current row from these resources.-->
                            <CollectionViewSource x:Key="VendorsCollection" Source="{Binding Vendors, Source={StaticResource CategoriesCollection}}" />
                            <CollectionViewSource x:Key="StylesCollection" Source="{Binding Styles, Source={StaticResource VendorsCollection}}" />
                            <CollectionViewSource x:Key="FinishesCollection" Source="{Binding Finishes, Source={StaticResource StylesCollection}}" />
                        </StackPanel.Resources>
                        <ComboBox                                                       
                                    IsSynchronizedWithCurrentItem="True"
                                    ItemsSource="{Binding Source={StaticResource VendorsCollection}}"
                                    SelectedItem="{Binding Finish.Style.Vendor}"
                                    DisplayMemberPath="Contact.Title"/>
                        <ComboBox
                                    IsSynchronizedWithCurrentItem="True"
                                    ItemsSource="{Binding Source={StaticResource StylesCollection}}"
                                    SelectedItem="{Binding Finish.Style}"
                                    DisplayMemberPath="Title"/>
                        <ComboBox
                                    IsSynchronizedWithCurrentItem="True"
                                    ItemsSource="{Binding Source={StaticResource FinishesCollection}}"
                                    SelectedItem="{Binding Finish}"
                                    DisplayMemberPath="Title"/>
                    </StackPanel>
                </DataTemplate>
            </DataGridTemplateColumn.CellEditingTemplate>
        </DataGridTemplateColumn>

    </DataGrid.Columns>
</DataGrid>
.

役に立ちましたか?

解決

私はあなたの質問に遭遇したばかりです。あなたはあなたの問題を解決しましたか?あなたの質問はこの1つ手に入れた。解決策があなたを助けることを願っています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top