2017-11-24 16 views
0

CATEGORY, DESCRIPTION의 데이터베이스가 하나 있습니다. 총 100 건. 100 Descriptions과 1Categories이 있으므로 분명히 Categories이 두 번 이상 사용됩니다. 예 :여러 개의 데이터 세트 및 여러 콤보 상자를 서로 연결하여 사용하는 MVVM

+----------+-------------+ 
| CATEGORY | DESCRIPTION | 
+----------+-------------+ 
| ACC  | DescAAAA | 
| ACC  | DescBBBB | 
| BMX  | DescCCCC | 
+----------+-------------+ 

는 I 번째 콤보 (DESCRIPTION)의 선택을 제한하는 제 콤보 (카테고리)를 사용할.

2 개의 ComboBox가 두 개의 DataSet TableAdaptors에 바인딩되어 있습니다. 각 TableAdaptor은 단순하지만 다른 스키마를 반환합니다.

콤보 상자 :

SELECT DISTINCT CATEGORY 
FROM EstimateInformationTable 
ORDER BY CATEGORY 

ComboBox2 :

SELECT DESCRIPTION 
FROM EstimateInformationTable 
WHERE (CATEGORY = @Category) 
ORDER BY DESCRIPTION 

내가 가지이 추가 ButtonClickEvent 사용하여 코드 숨김에서 일을 얻을 수 있지만, 분명이 내가 원하는 궁극적으로하지 않습니다.

범주 ComboBox를 변경하면 설명 ComboBox가 업데이트되도록 MVVM과 올바른 Notify Properties (필요한 작업 인 경우)를 사용하고 싶습니다.

이 작업은 항상 수행해야하지만이 작업을 처음 접했습니다. 나는 진전을 이루었지만, 나는이 일로 머리를 감싸는 데 어려움을 겪고있다. 이것은 스스로 부과 한 학습 운동이므로, 저를 위해 설명을 벙어리 채우십시오. 감사합니다, 마이크

XAML은 :

<Page 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:local="clr-namespace:gobo.Pages" 
     xmlns:gobo="clr-namespace:gobo" x:Class="gobo.Pages.TESTSTUFF01" 
     xmlns:vm="clr-namespace:gobo.ViewModel" 
     mc:Ignorable="d" 

     Title="TESTSTUFF01" Loaded="Page_Loaded"> 
    <Page.Resources> 
     <vm:CategoryChangedViewModel x:Key="CategoryChangedViewModel"/> 
     <gobo:gobo2018DataSet1 x:Key="gobo2018DataSet1"/> 
     <CollectionViewSource x:Key="estimateInformationTableViewSource" Source="{Binding EstimateInformationTable, Source={StaticResource gobo2018DataSet1}}"/> 
     <gobo:gobo2018EstimateInformationTableDescriptionDataSet x:Key="gobo2018EstimateInformationTableDescriptionDataSet"/> 
     <CollectionViewSource x:Key="estimateInformationTableViewSource1" Source="{Binding EstimateInformationTable, Source={StaticResource gobo2018EstimateInformationTableDescriptionDataSet}}"/> 
    </Page.Resources> 


    <Page.Background> 
     <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0"> 
      <GradientStop Color="Black" Offset="0"/> 
      <GradientStop Color="Red" Offset="1"/> 
     </LinearGradientBrush> 
    </Page.Background> 

    <StackPanel Orientation="Vertical" > 
     <Label Content="TEST STUFF 01 Tab Page1" VerticalAlignment="Top" Background="{x:Null}"/> 
     <Button Content="Change Description contents" Click="Button_Click"/> 
     <Grid x:Name="grid1" DataContext="{StaticResource estimateInformationTableViewSource}" HorizontalAlignment="Left" VerticalAlignment="Top"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto"/> 
       <ColumnDefinition Width="Auto"/> 
      </Grid.ColumnDefinitions> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto"/> 
      </Grid.RowDefinitions> 
      <Label Content="CATEGORY:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/> 

      <ComboBox x:Name="cATEGORYComboBox" Grid.Column="1" DisplayMemberPath="CATEGORY" HorizontalAlignment="Left" Height="Auto" Margin="3" Grid.Row="0" VerticalAlignment="Center" Width="120" 
         ItemsSource="{Binding}" 
         SelectedIndex="{Binding Category, Source={StaticResource CategoryChangedViewModel}}"> 
       <ComboBox.ItemsPanel> 
        <ItemsPanelTemplate> 
         <VirtualizingStackPanel/> 
        </ItemsPanelTemplate> 
       </ComboBox.ItemsPanel> 
      </ComboBox> 

     </Grid> 
     <Grid x:Name="grid2" DataContext="{StaticResource estimateInformationTableViewSource1}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="311"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto"/> 
       <ColumnDefinition Width="Auto"/> 
      </Grid.ColumnDefinitions> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto"/> 
      </Grid.RowDefinitions> 
      <Label Content="DESCRIPTION:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/> 
      <ComboBox x:Name="dESCRIPTIONComboBox" Grid.Column="1" DisplayMemberPath="DESCRIPTION" HorizontalAlignment="Left" Height="Auto" ItemsSource="{Binding}" Margin="3,9,-53,9" Grid.Row="0" VerticalAlignment="Center" Width="180"> 
       <ComboBox.ItemsPanel> 
        <ItemsPanelTemplate> 
         <VirtualizingStackPanel/> 
        </ItemsPanelTemplate> 
       </ComboBox.ItemsPanel> 
      </ComboBox> 
     </Grid> 
    </StackPanel> 


</Page> 

내가이 작품 것으로 나타났습니다하지만 가장 좋은 대답하면 내가 궁금

namespace gobo.Pages 
{ 
    /// <summary> 
    /// Interaction logic for TESTSTUFF01.xaml 
    /// </summary> 
    public partial class TESTSTUFF01 : Page 
    { 
     private gobo.gobo2018DataSet1 gobo2018DataSet1; 
     public gobo.gobo2018DataSet1TableAdapters.EstimateInformationTableTableAdapter gobo2018DataSet1TableAdapter; 
     private CollectionViewSource estimateInformationTableViewSource; 

     private gobo.gobo2018EstimateInformationTableDescriptionDataSet gobo2018EstimateInformationTableDescriptionDataSet; 
     private gobo.gobo2018EstimateInformationTableDescriptionDataSetTableAdapters.EstimateInformationTableTableAdapter EstimateInformationTableTableAdapter; 
     private CollectionViewSource estimateInformationTableViewSource1; 


     public TESTSTUFF01() 
     { 
      InitializeComponent(); 
     } 

     private void Page_Loaded(object sender, RoutedEventArgs e) 
     { 

      gobo2018DataSet1 = ((gobo.gobo2018DataSet1)(this.FindResource("gobo2018DataSet1"))); 
      gobo2018DataSet1TableAdapter = new gobo.gobo2018DataSet1TableAdapters.EstimateInformationTableTableAdapter(); 
      gobo2018DataSet1TableAdapter.Fill(gobo2018DataSet1.EstimateInformationTable); 
      estimateInformationTableViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("estimateInformationTableViewSource"))); 
      estimateInformationTableViewSource.View.MoveCurrentToFirst(); 

      gobo2018EstimateInformationTableDescriptionDataSet = ((gobo.gobo2018EstimateInformationTableDescriptionDataSet)(this.FindResource("gobo2018EstimateInformationTableDescriptionDataSet"))); 
      EstimateInformationTableTableAdapter = new gobo.gobo2018EstimateInformationTableDescriptionDataSetTableAdapters.EstimateInformationTableTableAdapter(); 
      EstimateInformationTableTableAdapter.FillByCategory(gobo2018EstimateInformationTableDescriptionDataSet.EstimateInformationTable,"ACC"); 
      estimateInformationTableViewSource1 = ((System.Windows.Data.CollectionViewSource)(this.FindResource("estimateInformationTableViewSource1"))); 
      estimateInformationTableViewSource1.View.MoveCurrentToFirst(); 


     } 

     public void LoadDescriptionToCbo(String parameter) 
     { 
      if(gobo2018EstimateInformationTableDescriptionDataSet != null) 
      { 
       EstimateInformationTableTableAdapter.FillByCategory(gobo2018EstimateInformationTableDescriptionDataSet.EstimateInformationTable, parameter); 
      } 

     } 

     private void Button_Click(object sender, RoutedEventArgs e) 
     { 
      LoadDescriptionToCbo("ACT"); 
      Console.WriteLine("Button Click -> LoadDescriptionToCode"); 
     } 
    } 
} 
+0

나는이 방법이 유용하다는 것을 알았지 만 그것이 가장 좋은 대답인지 궁금하다. – mjordan

답변

0

을 CurrentCodeBehind.

private void cATEGORYComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) 
     { 
      ComboBox cbx = (ComboBox)sender; 
      string s = ((DataRowView)cbx.Items.GetItemAt(cbx.SelectedIndex)).Row.ItemArray[0].ToString();  
      LoadDescriptionToCbo(s); 

     }