2016-10-03 20 views
0

私はwpfデータグリッドを使用しています。グループ化を使用してオーダー番号でグループを作成していますが、次のような各オーダーアイテムのステータスも持っています。どういうわけか、各注文の1つの項目が処理されている場合はという項目がすべて表示されているので、各項目の各ステータスを一覧表示すると画面に乱雑に見えますので、という項目があることを意味します。 (Expander header - DockPanel)ので、このように見えるかもしれません:WPF DataGrid Dockパネルグループ

注文番号:#1 - 注文が進行中です。


注文番号:#2 - 注文が進行中です。


注文番号:#3 - 注文が進行中ではありません。

enter image description here

そこで質問です:ここ

:) NEXTは、Number一部を注文する は、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から継承するオブジェクトを取得します。そのプロパティの1つはNameです。あなたのXAML関心の別の特性がItemsある

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

Nameと結合することができる理由です。これは、そのグループのすべてのビューモデルのリストです。今すぐ簡単にヘッダー内のアイテムのプロパティにアクセスすることができます

+0

説明ありがとうございますが、私はそれを何かすることができますか?#3 - プロセス中、ステータスと注文数をTextBlockのテキスト、正確に私のテキストブロックのテキストとして2つのプロパティorrders +ステータスを表示したい –

+0

他の場所と同じように、作成したテキストを自由に作成してスタイルを設定できます。私は2つの 'TextBlock'を(あなたがすでに持っているものではなく)あなたのケースの水平方向に配置された' StackPanel'で結合します。 – gomi42