none
WPF DataGrid Binding with parameter

    General discussion

  • Bonjour,

    I have to display 4000 seats very fastly, with a lot of graphical functions. I test then with a DataGrid in WPF. Each column also is indexed. Then, the binding must have a parameter. When I don't pass a paramter, it is good. But when I have a parameter, the loading send this message :

    System.Windows.Data Error: 17 : Cannot get 'ItemToString' value (type 'String') from '' (type 'ObservableCollectionLignePlaces'). BindingExpression:Path=ItemToString[104]; DataItem='ObservableCollectionLignePlaces' (HashCode=30840839); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String') TargetParameterCountException:'System.Reflection.TargetParameterCountException: Nombre de paramètres incorrects (wrong number of parameters)

    This is my code :

            Dim tbl As New ObservableCollectionLignesPlaces
            Dim k = 0
            For j = 0 To 19
                Dim row = New ObservableCollectionLignePlaces
                For i = 0 To 149
                    k += 1
                    Dim place = New Place With {.ID = k}
                    row.Add(place)
                Next
                tbl.Add(row)
            Next

            For i = 0 To 149
                Dim bind = New System.Windows.Data.Binding
                bind.Path = New PropertyPath("ItemToString[" & i & "]")
                Dim col = New System.Windows.Controls.DataGridTextColumn() With {.Binding = bind}
                WindowControlDessinPanel1.DataGrid1.Columns.Add(col)
            Next

            WindowControlDessinPanel1.DataGrid1.ItemsSource = tbl

    This is my data code :

    Public Class ObservableCollectionLignesPlaces
        Inherits Collections.ObjectModel.ObservableCollection(Of ObservableCollectionLignePlaces)
    End Class

    Public Class ObservableCollectionLignePlaces
        Inherits Collections.ObjectModel.ObservableCollection(Of Place)

        Default Public ReadOnly Property ItemToString(ByVal Index As Integer) As String
            Get
                Return Item(Index).ToString
            End Get
        End Property

    End Class

    Public Class Place
        Public ID As Integer

        Public Overrides Function ToString() As String
            Return CStr(ID)
        End Function
    End Class

     

    This is my XAML :

    <UserControl x:Name="userControl" x:Class="WindowControlDessinObjet"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="166" Height="38" BorderBrush="Black" BorderThickness="1" RenderTransformOrigin="0.5,0.5">
     <UserControl.Resources>
     </UserControl.Resources>
     <UserControl.RenderTransform>
      <TransformGroup>
                <TranslateTransform x:Name="myTranslateTransform" x:FieldModifier="Public"/>
                <ScaleTransform x:Name="myScaleTransform" ScaleX="1" ScaleY="1" x:FieldModifier="Public"/>
            </TransformGroup>
     </UserControl.RenderTransform>
        <Grid x:Name="GrillePrincipale" Background="White" x:FieldModifier="Public">
         <Canvas x:Name="CanvasLabel" Margin="0"  x:FieldModifier="Public">
          <Label x:Name="LabelPrincpal" Margin="0" Content="Lael" FontSize="16" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" x:FieldModifier="Public" VerticalAlignment="Center" SnapsToDevicePixels="True"  Width="164" Canvas.Top="3.343"  />
                <Canvas.RenderTransform>
                    <TransformGroup>
                        <TranslateTransform x:Name="TranslateTransformCanvasLabel" x:FieldModifier="Public"/>
                        <ScaleTransform ScaleX="1" ScaleY="1" x:Name="ScaleTransformCanvasLabel" x:FieldModifier="Public"/>
                        <RotateTransform Angle="0" x:Name="RotateTransformCanvasLabel" x:FieldModifier="Public"/>
                    </TransformGroup>
                </Canvas.RenderTransform>
            </Canvas>
               
        </Grid>
    </UserControl>

    Friday, July 01, 2011 3:48 PM

All replies

  • The good XAML code :

     

    <UserControl x:Class="WindowControlDessinPanel"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="300" Height="300">
        <Grid Margin="0,0,-1,-7.09">
            <Slider x:Name="zoomSlider1" Minimum="0.1" Maximum="5" Value="3" Height="27" VerticalAlignment="Top" Margin="8,0,7,0" />
            <ScrollViewer HorizontalScrollBarVisibility="Auto" Margin="8,153,7.125,14.285">
                <Canvas x:Name="canvas1" Width="600" Height="400" Background="#FFFAF6F6" x:FieldModifier="Public">
                    <Canvas.LayoutTransform>
                        <ScaleTransform ScaleX="{Binding Value, ElementName=zoomSlider1}" ScaleY="{Binding Value, ElementName=zoomSlider1}" />
                    </Canvas.LayoutTransform>
                    <Grid x:Name="GrillePrincipale" x:FieldModifier="Public">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <DataGrid AutoGenerateColumns="False" Name="DataGrid1" x:FieldModifier="Public" FontSize="5"  Margin="0,0,0,0"  />
                    </Grid>
                 </Canvas>
            </ScrollViewer>
            <Image Margin="8,33,0,0" Name="Image1" x:FieldModifier="Public" Stretch="None" HorizontalAlignment="Left" Width="281" Height="114" VerticalAlignment="Top" />
        </Grid>
    </UserControl>

    Friday, July 01, 2011 3:56 PM