2011-07-21 8 views
5

Poniżej znajduje się XAML. Dane z obiektu wypełniają listę. Po prostu nie mogę wyświetlić grup. Chcę zgrupować na właściwości o nazwie workcenter, która nie jest wyświetlana w widoku listy, ale nadal jest częścią klasy do niej przypisanej.Nagłówki grup widoku listy w WPF nie wyświetlają się: jakieś pomysły?

Jestem noobem WPF, więc wybacz mi, jeśli odpowiedź jest tuż przede mną i tęsknię za nią. Korzystam z przykładów z internetu, aby spróbować to zrobić, ale to nie jest do tego momentu.

To jest makieta do projektu, który muszę zrobić, więc zignoruj ​​głupi tekst i przestrzeń nazw. =)

<Window x:Class="Son_of_a_Batching_WPF_Mock_up.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    DataContext="{Binding RelativeSource={RelativeSource Self}}" 
    Title="You Son of a Batch. I'm Detective John Kimble! I'm A Cop You Idiot!" Height="600" Width="800"> 
    <Window.Resources> 
     <CollectionViewSource Source="{Binding testDataCollection}" 
           x:Key="src"> 
      <CollectionViewSource.GroupDescriptions> 
       <PropertyGroupDescription PropertyName="workcenter" /> 
      </CollectionViewSource.GroupDescriptions> 
     </CollectionViewSource> 
    </Window.Resources> 
    <Grid x:Name="mainGrid" Background="White"> 
     <ComboBox x:Name="cboWorkCenters" HorizontalAlignment="Left" VerticalAlignment="Top" Width="256" Background="{x:Null}" Margin="12,50,0,0" SelectedIndex="0" FontSize="12pt" Height="27.28"> 
      <ComboBoxItem Content="Group by work center" FontSize="12pt"/> 
      <ComboBoxItem Content="Group by batch type" FontSize="12pt"/> 
     </ComboBox> 
     <Label x:Name="lblFilter" FontSize ="12pt" HorizontalAlignment="Left" Margin="11.473,13.043,0,0" VerticalAlignment="Top" Content="Filter by work center:" Width="252.527" FontWeight="Bold"/> 
     <ListView x:Name="lvBatches" Margin="12,83,12,12" ItemsSource="{Binding Source = {StaticResource src}}"><!--ItemsSource="{Binding testDataCollection}">--> 

      <ListView.GroupStyle> 
       <GroupStyle> 
        <GroupStyle.ContainerStyle> 
         <Style TargetType="{x:Type GroupItem}"> 
          <Setter Property="Margin" Value="0,0,0,5"/> 
          <Setter Property="Template"> 
           <Setter.Value> 
            <ControlTemplate TargetType="{x:Type GroupItem}"> 
             <Expander IsExpanded="True" BorderBrush="#FFA4B97F" BorderThickness="0,0,0,1"> 
              <Expander.Header> 
               <DockPanel> 
                <TextBlock FontWeight="Bold" Text=" {Binding Path=name}" Margin="5,0,0,0" Width="100"/> 
                <TextBlock FontWeight="Bold" Text=" {Binding Path=itemcount}"/> 
               </DockPanel> 
              </Expander.Header> 
              <Expander.Content> 
               <ItemsPresenter /> 
              </Expander.Content> 
             </Expander> 
            </ControlTemplate> 
           </Setter.Value> 
          </Setter> 
         </Style> 
        </GroupStyle.ContainerStyle> 
       </GroupStyle> 
      </ListView.GroupStyle> 

      <ListView.View> 
       <GridView> 
        <GridViewColumn x:Name="colID" Header="Batch ID" Width="200" DisplayMemberBinding="{Binding id}"/> 
        <!--<GridViewColumn x:Name="colWC" Header="Work Center" Width="100" DisplayMemberBinding="{Binding workcenter}"/>--> 
        <GridViewColumn x:Name="colStart" Header="Start Time" Width="150" DisplayMemberBinding="{Binding start}"/> 
        <GridViewColumn x:Name="colEnd" Header="End Time" Width="150" DisplayMemberBinding="{Binding end}"/> 
        <GridViewColumn x:Name="colDur" Header="Duration" Width="100" DisplayMemberBinding="{Binding duration}"/> 
        <GridViewColumn x:Name="colBatchType" Header="Batch Type" Width="100" DisplayMemberBinding="{Binding batchtype}"/> 
       </GridView> 
      </ListView.View> 
     </ListView> 
    </Grid> 
</Window> 

Ponieważ nie mogę publikować zdjęć, postaram się określić, jak to wygląda, używając umiejętności tekstowych. Otrzymuję:

**Batch ID Start Time End Time Duration Batch Type** 
-------- ---------- -------- -------- ---------- 
12344555 7/21/11  7/22/11  100  Loaded 
54564564 7/21/11  7/23/11  50  Sequential 
12433555 7/21/11  7/22/11  100  Loaded 
54564564 7/21/11  7/23/11  50  Sequential 
12311555 7/21/11  7/22/11  100  Loaded 
54456564 7/21/11  7/23/11  50  Sequential 
12344555 7/21/11  7/22/11  100  Loaded 
57744564 7/21/11  7/23/11  50  Sequential 
12994555 7/21/11  7/22/11  100  Loaded 
54500564 7/21/11  7/23/11  50  Sequential 

Chcę tego, ponieważ 332, 404 to grupy.

**Batch ID Start Time End Time Duration Batch Type** 
-------- ---------- -------- -------- ---------- 
**332** 
12344555 7/21/11  7/22/11  100  Loaded 
12433555 7/21/11  7/22/11  100  Loaded 
12311555 7/21/11  7/22/11  100  Loaded 

**404** 
54564564 7/21/11  7/23/11  50  Sequential 
54564564 7/21/11  7/23/11  50  Sequential 
54500564 7/21/11  7/23/11  50  Sequential 

Oto kod za. Nie sądzę, że to pomoże. Większość to tylko dane testowe do wyświetlenia w makiecie.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 
using System.Collections.ObjectModel; 

namespace Son_of_a_Batching_WPF_Mock_up 
{ 
    /// <summary> 
    /// Interaction logic for Window1.xaml 
    /// </summary> 
    public partial class Window1 : Window 
    { 
     private ObservableCollection<TestData> _testDataCollection = new ObservableCollection<TestData>(); 
     public ObservableCollection<TestData> testDataCollection { get { return _testDataCollection; } } 
     //public System.ComponentModel.ICollectionView source { get; set; } 

     public Window1() 
     { 
      InitializeComponent(); 
      //this.source.GroupDescriptions.Add(new PropertyGroupDescription("workcenter")); 

      LoadTestData(); 

     } 

     private void LoadTestData() 
     { 
      //int[] icnt = new int[529]; 
      for (int i = 0; i <= 99; i++) 
      { 
       _testDataCollection.Add(new TestData()); 
      } 
      //for (int i = 0; i < _testDataCollection.Count; i++) 
      //{ 
      // icnt[int.Parse(_testDataCollection[i].workcenter)] ++; 
      //} 
      //this.label1.Content = "332:" + icnt[332].ToString() + "," + "402:" + icnt[402].ToString() + ","+ "404:" + icnt[404].ToString() + "," 
      //  + "522:" + icnt[522].ToString() + ","+ "523:" + icnt[523].ToString() + ","+ "524:" + icnt[524].ToString() + "," 
      //  + "527:" + icnt[527].ToString() + ","+ "528:" + icnt[528].ToString() + ","; 
     } 
    } 

    public class TestData 
    { 
     private string[] _WCs = new string[] { "404", "527", "523", "524", "332", "528", "522", "402" }; 
     private string[] _workcenters = new string[1000]; 
     private string _workcenter; 
     private double _duration = 0; 

     public string id 
     { 
      get { return Guid.NewGuid().ToString(); } 
     } 

     public string workcenter 
     { 
      get 
      { 
       return _workcenter; 
      } 
     } 

     public DateTime start 
     { 
      get { return DateTime.Now; } 
     } 

     public DateTime end 
     { 
      get { return DateTime.Now; } 
     } 

     public double duration 
     { 
      get 
      { 
       return _duration; 
      } 
     } 

     public string batchtype 
     { 
      get 
      { 
       switch (workcenter) 
       { 
        case "332": 
        case "402": 
        case "527": 
         return "Loaded Batch"; 
        case "404": 
        case "524": 
         return "Sequential Batch"; 
        case "522": 
        case "528": 
        case "523": 
         return "Supervisor Batch"; 
        default: 
         return ""; 
       } 
      } 
     } 

     public TestData() 
     { 
      RandomizeWCs(); 
      Random rnd = new Random(); 
      _workcenter = _workcenters[rnd.Next(0, 999)]; 
      rnd = new Random(); 
      _duration = rnd.Next(10, 60); 
     } 

     private void RandomizeWCs() 
     { 
      Random rnd = new Random(); 
      int iIndex, i; 

      while (_workcenters.Contains(null)) 
      { 
       iIndex = rnd.Next(1000); 
       i = rnd.Next(8); 
       if (_workcenters[iIndex] == null) 
       { 
        _workcenters[iIndex] = _WCs[i]; 
       } 
      } 
     } 

    } 
} 
+0

Co wyświetla, cokolwiek w ogóle? – CodingGorilla

+0

Dostaję teraz wszystko, aby poprawnie grupować, tylko tekst grupy nie jest wyświetlany. Tak więc, w zasadzie przykład poniżej "To czego chcę, to to, że 332, 404 to grupy". tylko bez wyświetlania ** 332 ** i ** 404 **. Niestety nie mogę opublikować zdjęć. – Yatrix

+2

Dostajesz mój głos na nazwę "Son_of_a_Batching", ty sprytny podstępny bastage! (UWAGA: jest to odniesienie do filmu "Johnny Dangerously") http://www.imdb.com/title/tt0087507/quotes –

Odpowiedz

3

Unreal: Od wielu godzin walę głową w ścianę i jestem zażenowany, mówiąc, że rozwiązałem swój problem. Rozwiązanie?

<TextBlock FontWeight="Bold" Text=" {Binding Path=name}" Margin="5,0,0,0" Width="100"/> 
<TextBlock FontWeight="Bold" Text=" {Binding Path=itemcount}"/> 

Freaking nazwa i itemcount nie były pisane wielkimi literami !!! Daj mi sekundę, żeby uderzyć się w twarz ... no proszę ... Wróciłem. Nazwa i ItemCount to właściwy sposób kodowania tego.

Dzięki za pomoc dla wszystkich, którzy odpowiedzieli.

+2

było tam tyle razy ... 1001+ za uderzenie się w twarz! – LucasS

Powiązane problemy