bind column in silverlight datagrid to property that accepts parameter

ChaimARinger
ChaimARinger used Ask the Experts™
on
class cls1
property p1

class cls2
property cls1


list of cls2
the datagrid is bound to list
I want to bind col to cls1.p1
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Let me explain the question better.
How is it possilbe to bind a column to complex data
like text="{binding prop1.prop2}" instead of a plain text="{binding prop1}"

Another posibility would be for me if prop1 has a parameter so to write something like
 text="{binding prop1[param]}"

All those solution do not raise errors but nothing is returned. I would really appreciate some help on this one.
Thanks
The attached code targets WPF but should be the same, I hope, for Silverlight.

It produces 3 side-by-side listboxes
The first is populated via a Class3 property returning an instance of Class2
The second gets it's data direct from Class2
The third uses a parameter set in the XAML to determine the number of entries in the list
<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:l="clr-namespace:BindingTest"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <ObjectDataProvider x:Key="DataProvider" ObjectType="{x:Type l:Class1}">
            <ObjectDataProvider.ConstructorParameters>
                <sys:Int32>7</sys:Int32>
            </ObjectDataProvider.ConstructorParameters>
        </ObjectDataProvider>
        <l:Class2 x:Key="DP2"/>
        <l:Class3 x:Key="DP3"/>
    </Window.Resources>
    <StackPanel Orientation="Horizontal" DataContext="{StaticResource DP3}">
        <ListBox ItemsSource="{Binding C2List}" DataContext="{Binding Class2Ref}"/>
        <ListBox ItemsSource="{Binding C2List}" DataContext="{StaticResource DP2}"/>
        <ListBox ItemsSource="{Binding C1List}" DataContext="{StaticResource DataProvider}"/>
    </StackPanel>
</Window>

Public Class Class1
    Dim _list As New List(Of Integer)
    Public Sub New(ByVal count As Integer)
        For i = 1 To count
            _list.Add(i)
        Next

    End Sub
    Public ReadOnly Property C1List() As List(Of Integer)
        Get
            Return _list
        End Get
    End Property
End Class

Public Class Class2
    Public ReadOnly Property C2List() As List(Of String)
        Get
            Return New List(Of String)(New String() {"AAAA", "BBBB", "CCCC", "CCCC"})
        End Get
    End Property
End Class

Public Class Class3
    Public ReadOnly Property Class2Ref() As Class2
        Get
            Return New Class2
        End Get
    End Property
End Class

Open in new window

Author

Commented:
It does not look that it works in silverlight
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Which piece doesn't work?
What are the symptoms?
Any error messages?

Author

Commented:
windows does not have a recource child
Window is a WPF element - I think it would be Canvas in Silverlight.
As I said, the xaml I posted targets WPF and will need detail changes for Silverlight.
The intention was that the approach - using StaticResource, ObjectDataProvider, etc would be valid.
AshokSr. Software Engineer

Commented:
Try

    <UserControl.Resources>
        <ObjectDataProvider x:Key="DataProvider" ObjectType="{x:Type l:Class1}">
            <ObjectDataProvider.ConstructorParameters>
                <sys:Int32>7</sys:Int32>
            </ObjectDataProvider.ConstructorParameters>
        </ObjectDataProvider>
        <l:Class2 x:Key="DP2"/>
        <l:Class3 x:Key="DP3"/>
    </UserControl.Resources>

HTH
Ashok

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial