2016-10-03 12 views
0

wpf DataGrid를 사용하고 있으며 그룹화를 사용하여 주문 수를 그룹화하고 각 주문 항목에 대한 상태도 표시합니다. 진행 여부 어떻게 든 그것은 각 항목의 각 상태를 나열하면 화면에 지저분 해 보입니다. 왜냐하면 은 각 주문 중 하나의 항목이 진행 중이므로 모든 항목도 처리된다는 것을 의미하므로이므로 주문 번호 옆에 상태를 이동할 수 있는지 궁금합니다. (Expander header - DockPanel) 그러면 다음과 같이 보일 수 있습니다.WPF DataGrid Dock 패널 그룹화

주문 번호 : # 1 - 주문 진행 중입니다.


주문 번호 : # 2 - 주문이 진행 중입니다.


주문 번호 : # 3 - 주문이 진행되지 않습니다.

enter image description here

그래서 질문은 : 이 번호 부분을 주문 '주문 현황'NEXT를 이동하는 IT 가능하다 :) 여기

내 코드입니다 :

<DataGrid.GroupStyle> 
     <!-- Style for groups at top level. --> 
     <GroupStyle> 
      <GroupStyle.ContainerStyle> 
       <Style TargetType="{x:Type GroupItem}"> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate TargetType="{x:Type GroupItem}"> 
           <Expander IsExpanded="True" Background="Black" Opacity="0.7"> 
            <Expander.Header > 
             <DockPanel Height="50" Margin="0,0,0,0" Name="dockPanel" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=ActualWidth}"> 
               <Button Name="btnFinishOrder" Content="Finish order" Margin="0,0,55,5" DockPanel.Dock="Right" Click="btnFinishOrder_Click" FontSize="12" BorderThickness="1.5" HorizontalAlignment="Left" VerticalAlignment="Bottom" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="#83D744" Background="Transparent" BorderBrush="#83D744" Width="130" Height="40"> 
                <Button.Template> 
                 <ControlTemplate TargetType="Button"> 
                  <Border BorderThickness="{TemplateBinding BorderThickness}" 
                  BorderBrush="{TemplateBinding BorderBrush}" 
                  Background="{TemplateBinding Background}"> 
                   <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> 
                  </Border> 
                 </ControlTemplate> 
                </Button.Template> 
               </Button> 

               <Button Name="btnTakeIt" Click="btnTakeIt_Click" Content="Take it!" Margin="0,0,20,5" DockPanel.Dock="Right" FontSize="12" BorderThickness="1.5" HorizontalAlignment="Left" VerticalAlignment="Bottom" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="#83D744" Background="Transparent" BorderBrush="#83D744" Width="130" Height="40"> 
                <Button.Template> 
                 <ControlTemplate TargetType="Button"> 
                  <Border BorderThickness="{TemplateBinding BorderThickness}" 
                  BorderBrush="{TemplateBinding BorderBrush}" 
                  Background="{TemplateBinding Background}"> 
                   <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> 
                  </Border> 
                 </ControlTemplate> 
                </Button.Template> 
               </Button> 
               <TextBlock FontWeight="Normal" FontFamily="Verdana" FontSize="20" Height="25" Foreground="#83D744" Text="{Binding Path=Name,StringFormat= Order Number:# {0}}" /> 
              </DockPanel> 
            </Expander.Header> 
            <Expander.Content> 
             <ItemsPresenter /> 
            </Expander.Content> 
           </Expander> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
       </Style> 
      </GroupStyle.ContainerStyle> 
     </GroupStyle> 
    </DataGrid.GroupStyle> 
</DataGrid> 

코드 숨김 :

public partial class MainWindow : Window 
{ 
    CollectionViewSource collectionViewSource = new CollectionViewSource(); 

    public MainWindow() 
    { 
     try 
     { 


      InitializeComponent(); 


      this.WindowStartupLocation = WindowStartupLocation.CenterScreen; 
      this.WindowState = WindowState.Maximized; 

      var ordersList = OrdersController.localOrders(); 

      collectionViewSource.Source = ordersList; 
      collectionViewSource.GroupDescriptions.Add(new PropertyGroupDescription("NumberOfOrder")); 
      DataContext = collectionViewSource; 

      DispatcherTimer timer = new DispatcherTimer(); 
      timer.Interval = TimeSpan.FromSeconds(1000); 
      timer.Tick += timer_Tick; 
      timer.Start(); 

     } 
     catch(Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 

    } 
} 

답변

1

Expander.Header은보기 모델 중 하나를 DataContext으로 가져 오지 않습니다. 대신 헤더는 CollectionViewGroup에서 상속받은 객체를 가져옵니다. 속성 중 하나는 Name입니다. 당신이 당신의 XAML 관심의 또 다른 속성은 Items입니다

<TextBlock ... Text="{Binding Path=Name,StringFormat= Order Number:# {0}}" /> 

Name에 결합 할 수있는 이유입니다. 그 그룹의 모든보기 모델 목록입니다. 이제 헤더에 대한 설명은

<TextBlock ... Text="{Binding Path=Items[0].MyProperty}" /> 
+0

감사 항목의 속성에 액세스하기 쉽습니다하지만 난 그것을 위해 수 같은 것을 만들 수있는 방법 # 3 -이 과정에서 뭔가 내가 같은 순서의 상태와 수를 유지하려는처럼 TextBlock의 텍스트, 능동적 인 성격 + 주문의 수 + 상태를 내 텍스트 블록의 텍스트로 표시하려합니다 –

+0

다른 곳에서와 마찬가지로 결과 텍스트를 자유롭게 만들고 스타일을 지정할 수 있습니다. 두개의'TextBlock'을 가로로 정렬 한'StackPanel' (당신이 이미 가지고있는 것 대신에)에 결합 할 것입니다. – gomi42