2016-06-04 13 views
0

Ich entwickle eine UWP Anwendung. Hier möchte ich wie unten Daten in einer Tabelle Format zeigen,Kann MyToolKit.Extended DataGrid in UWP nicht behandeln

enter image description here

Hier ist mein Ziel I Artikel suchen und diejenigen zu diesem Raster hinzuzufügen. mit out Daten im Raster Wenn ich auf Abgerundete Schaltfläche klicken (rote Farbe ist es eine DataGrid-Header-Vorlage) es funktioniert gut, aber wenn Raster enthält einige Daten in diesem Fall, wenn ich auf abgerundete Schaltfläche klicken unhand-led Exception wie,

enter image description here

Hier bin ich Platzieren Sie den Code, die ich verwendet habe,

<controls:DataGrid x:Name="dgNewBill" Grid.Row="0" Grid.Column="0" MinHeight="500" HorizontalAlignment="Left" HeaderBackground="Black" DefaultOrderIndex="1" Background="Black" RowBackgroundEvenBrush="Black" RowBackgroundOddBrush="Black" > 
           <controls:DataGrid.RowStyle> 
            <Style TargetType="ListBoxItem"> 
             <Setter Property="Padding" Value="0"></Setter> 
             <Setter Property="HorizontalAlignment" Value="Stretch"></Setter> 
            </Style> 
           </controls:DataGrid.RowStyle> 

           <controls:DataGrid.Columns> 
            <controls:DataGridTextColumn Width="50" Binding="{Binding SNumber}" Foreground="White" 
        IsAscendingDefault="False" CanSort="False"> 
             <controls:DataGridTextColumn.Header> 
              <Button x:Uid="RSNO" Height="40" Width="50" HorizontalAlignment="Left" Style="{StaticResource RoundButtonTemplate}" Margin="-10,0,0,0"/> 
             </controls:DataGridTextColumn.Header> 
             <controls:DataGridTextColumn.Style> 
              <Style TargetType="TextBlock"> 
               <Setter Property="TextAlignment" Value="Center"></Setter> 
              </Style> 
             </controls:DataGridTextColumn.Style> 
            </controls:DataGridTextColumn> 

            <!--Item Column--> 
            <controls:DataGridTextColumn Width="380" Binding="{Binding description}" Foreground="White" CanSort="False"> 
             <controls:DataGridTextColumn.Header> 
              <Button x:Uid="RItem" Height="40" Width="380" Style="{StaticResource RoundButtonTemplate}" Margin="-12,0,0,0"/> 
             </controls:DataGridTextColumn.Header> 
             <controls:DataGridTextColumn.Style> 
              <Style TargetType="TextBlock"> 
               <Setter Property="TextAlignment" Value="Center"></Setter> 
              </Style> 
             </controls:DataGridTextColumn.Style> 
            </controls:DataGridTextColumn> 
            <!--UOM column--> 
            <controls:DataGridTextColumn Width="120" Binding="{Binding uom}" Foreground="White" CanSort="False"> 
             <controls:DataGridTextColumn.Header> 
              <Button x:Uid="RUOM" Height="40" Width="120" Style="{StaticResource RoundButtonTemplate}" Margin="-12,0,0,0"/> 
             </controls:DataGridTextColumn.Header> 
             <controls:DataGridTextColumn.Style> 
              <Style TargetType="TextBlock"> 
               <Setter Property="TextAlignment" Value="Center"></Setter> 
              </Style> 
             </controls:DataGridTextColumn.Style> 
            </controls:DataGridTextColumn> 
            <!--Price Column--> 
            <controls:DataGridTemplatedColumn> 
             <controls:DataGridTemplatedColumn.Header> 
              <Button x:Uid="RPrice" Height="40" Width="110" Style="{StaticResource RoundButtonTemplate}" Margin="-12,0,0,0"/> 
             </controls:DataGridTemplatedColumn.Header> 
             <controls:DataGridTemplatedColumn.CellTemplate> 
              <DataTemplate> 
               <StackPanel Name="pricePanel" Width="110" Height="30" Tapped="pricePanel_Tapped" > 
                <TextBlock Name="price" Foreground="White" Text='{Binding price}' VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,5,0,0"></TextBlock> 
               </StackPanel> 
              </DataTemplate> 
             </controls:DataGridTemplatedColumn.CellTemplate> 
            </controls:DataGridTemplatedColumn> 


            <!--Qty Column--> 
            <controls:DataGridTemplatedColumn> 
             <controls:DataGridTemplatedColumn.Header> 
              <Button x:Uid="RQty" Height="40" Width="110" Style="{StaticResource RoundButtonTemplate}" Margin="-25,0,0,0"/> 
             </controls:DataGridTemplatedColumn.Header> 
             <controls:DataGridTemplatedColumn.CellTemplate> 
              <DataTemplate> 
               <StackPanel Name="quantityPanel" Width="50" Height="30" Tapped="quantityPanel_Tapped"> 
                <TextBlock Name="quantity" Foreground="White" Text='{Binding quantity}' VerticalAlignment="Center" Margin="0,5,0,0"></TextBlock> 
               </StackPanel> 
              </DataTemplate> 
             </controls:DataGridTemplatedColumn.CellTemplate> 
            </controls:DataGridTemplatedColumn> 

            <!--Discount Column--> 
            <controls:DataGridTemplatedColumn> 
             <controls:DataGridTemplatedColumn.Header> 
              <Button x:Uid="Rdiscount" Height="40" Width="60" Style="{StaticResource RoundButtonTemplate}" Margin="-25,0,0,0"/> 
             </controls:DataGridTemplatedColumn.Header> 
             <controls:DataGridTemplatedColumn.CellTemplate> 
              <DataTemplate> 
               <StackPanel Name="discountPanel" Width="60" Height="30" Tapped="discountPanel_Tapped" > 
                <TextBlock Name="Discount" Foreground="White" Text='{Binding discount}' VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,5,0,0"></TextBlock> 
               </StackPanel> 
              </DataTemplate> 
             </controls:DataGridTemplatedColumn.CellTemplate> 
            </controls:DataGridTemplatedColumn> 

            <!--Cost Column--> 
            <controls:DataGridTextColumn Width="110" Binding="{Binding cartTotal}" Foreground="White" CanSort="False" > 
             <controls:DataGridTextColumn.Header> 
              <Button x:Uid="RCartTotal" Height="40" Width="110" Style="{StaticResource RoundButtonTemplate}" Margin="-25,0,0,0"/> 
             </controls:DataGridTextColumn.Header> 
             <controls:DataGridTextColumn.Style> 
              <Style TargetType="TextBlock"> 
               <Setter Property="TextAlignment" Value="Center"></Setter> 
              </Style> 
             </controls:DataGridTextColumn.Style> 
            </controls:DataGridTextColumn> 

           <!--void image column--> 
            <controls:DataGridTemplatedColumn> 
             <controls:DataGridTemplatedColumn.Header> 
              <Button Name="Cancelbtn" Height="50" Click="Cancelbtn_Click" Width="55" > 
               <Image Source="/Images/erase.png" Name="ImgClearCartp" Height="40" Width="40" ></Image> 
              </Button> 
             </controls:DataGridTemplatedColumn.Header> 
             <controls:DataGridTemplatedColumn.CellTemplate> 
              <DataTemplate> 
               <StackPanel Name="voidImagePanel" Width="50" Height="30" Tapped="voidImagePanel_Tapped" > 
                <Image Name="VoidImage" Source='{Binding imageUrl}' Height="20" Width="30" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,5,0,0"></Image> 
               </StackPanel> 
              </DataTemplate> 
             </controls:DataGridTemplatedColumn.CellTemplate> 
            </controls:DataGridTemplatedColumn> 
           </controls:DataGrid.Columns> 
          </controls:DataGrid> 

ich habe getestet und nach meinem Verständnis, wegen mit DataGridTemplatedColumn diese Ausnahme bekommen. Aber nach meinem Umfang muss ich TemplateColumn statt DataGridTextColumn verwenden.

Und ich habe https://github.com/MyToolkit/MyToolkit/wiki/DataGrid

Link verwendet. Bitte schlagen Sie mir vor, wie kann ich dieses Problem lösen?

+0

Vielleicht ist es besser Schreib Problem auf Github wäre? –

Antwort

1

Ich habe getestet und nach meinem Verständnis, wegen der Verwendung von DataGridTemplatedColumn bekommen diese Ausnahme. Aber gemäß meinem Bereich muss ich TemplateColumn anstelle von DataGridTextColumn verwenden.

Ja, für dieses Problem ist eine Abhilfe DataGridTemplatedColumn-DataGridTextColumn .Aber es gibt andere zwei Abhilfen verwenden Sie können zu ersetzen, die ich denke, besser als direkt zu ersetzen.

  • können Sie die order Eigenschaft wie Order="{Binding imageUrl}" für die DataGridTemplatedColumn hinzufügen wie folgt:

    <controls:DataGridTemplatedColumn Order="{Binding imageUrl}"> 
    <controls:DataGridTemplatedColumn.Header> 
        <Button Name="Cancelbtn" 
          Width="55" 
          Height="50" 
          Background="Green" 
          Click="Cancelbtn_Click"> 
         <Image Name="ImgClearCartp" 
           Width="40" 
           Height="40" 
           Source="Assets/cafee2.jpg" /> 
        </Button> 
    </controls:DataGridTemplatedColumn.Header> 
    <controls:DataGridTemplatedColumn.CellTemplate> 
        <DataTemplate> 
         <StackPanel Name="voidImagePanel" 
            Width="50" 
            Height="30" 
            Tapped="voidImagePanel_Tapped"> 
          <Image Name="VoidImage" 
            Width="30" 
            Height="20" 
            Margin="0,5,0,0" 
            HorizontalAlignment="Left" 
            VerticalAlignment="Center" 
            Source="{Binding imageUrl}" /> 
         </StackPanel> 
        </DataTemplate> 
    </controls:DataGridTemplatedColumn.CellTemplate> 
    
  • Wenn Sie Sie haben einfach nicht die Spalte sortieren müssen, um die CanSort="False" für das DataGridTemplatedColumn Element hinzufügen können, wie folgt:

    <controls:DataGridTemplatedColumn CanSort="False"> 
    ... 
    </controls:DataGridTemplatedColumn.CellTemplate> 
    

    der Grund für die Ausnahme von MyToolkit die 0.123.609 istEigenschaft von DataGridTemplatedColumn Element ist null initial, aber um path Parameter daraus zu erhalten, wie folgendes Bild zeigt.Sie ​​können dieses Problem auch an MyToolKit issues senden, um das MyToolKit-Team zu bitten, es zu beheben.

enter image description here

+0

Ja, Sie sind richtig.Grid hat Bilder und in der Standardeinstellung ist die Sortierung aktiviert, deshalb wegen der Sortierung dieses Problem zu bekommen. Nachdem Sie die Anzahl der Versuche erreicht haben, erhalten Sie die Lösung. Kleine Korrektur für Ihre Lösung ist ** Bestellung ** Die Verwendung ist nicht erforderlich. Danke @Sunteen – Sagar