Solved

XAML DATA BINDING LISTVIEW PROBLEM

Posted on 2014-09-26
12
299 Views
Last Modified: 2014-09-30
Hi all,
I am having a problem binding data to a listview with three objects per item.  I have a static image, and two textboxes one a top the other.  I am getting the following error....

Error: BindingExpression path error: 'Name' property not found on 'Char16'. BindingExpression: Path='Name' DataItem='Char16'; target element is 'Windows.UI.Xaml.Controls.TextBlock' (Name='null'); target property is 'Text' (type 'String')

'My XAML......
<Page
    x:Class="RuSafeWP.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:RuSafeWP"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" Height="665.756">
    <Page.BottomAppBar>
        <CommandBar>
            <AppBarButton x:Name="btnADD" Icon="Add" Label="Add"/>
            <AppBarButton x:Name="btnDelete" Icon="Delete" Label="Delete"/>
        </CommandBar>
    </Page.BottomAppBar>

    <Grid RequestedTheme="Light" Background="White" RenderTransformOrigin="0.473,0.725" HorizontalAlignment="Left" Margin="0,0,0,-0.167" Width="400">
        <Grid.RowDefinitions>
            <RowDefinition Height="18*"/>
            <RowDefinition Height="11*"/>
        </Grid.RowDefinitions>
        <Image x:Name="imgMAIN" HorizontalAlignment="Left" Height="100" Margin="50,68,0,0" VerticalAlignment="Top" Width="295" Source="Assets/RuSafe Splash.png"/>
        <TextBlock x:Name="txtVERSION" HorizontalAlignment="Left" Margin="243,10,0,0" TextWrapping="Wrap" Text="Version: " VerticalAlignment="Top" Width="147" RequestedTheme="Dark" Foreground="#FF000108" FontSize="14"/>
        <TextBlock x:Name="OutputTextBlock" HorizontalAlignment="Left" Margin="50,35,0,350.333" TextWrapping="Wrap" Text="TextBlock" Width="295"/>
        <ListView x:Name="lvRUSAFE_FILES" 
                  HorizontalAlignment="Left" 
                  Height="401" 
                  Margin="10,195,0,0" 
                  VerticalAlignment="Top" 
                  Width="380" 
                  Grid.RowSpan="2"
                  ItemsSource="{Binding}"
                  DataContext="RSCatalogs"
                  >

            <ListView.ItemTemplate>
                <DataTemplate>

                <StackPanel Orientation="Horizontal" Height="75">
                    <Image Source="/Assets/stock_lock.png" Height="73" Width="73"/>

                <StackPanel Width="370">
                     <TextBlock Text="{Binding Name}"
                     Foreground="#FFC8AB14" FontSize="28" FontWeight="Bold" />

                    <TextBlock Text="{Binding DTLW}"
                     TextWrapping="Wrap" FontSize="18" />
                </StackPanel>
            </StackPanel>

                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Page>

Open in new window


'My Code Behind
Dim local As StorageFolder = PARENT_PATH

        If local IsNot Nothing Then
            Try
                ' Get the DataFolder folder.

                Dim dataFolder = Await local.GetFolderAsync("RuSafe")
                Dim files = dataFolder.GetFilesAsync()
                Dim _RC As RSCatalogs = Nothing

                ' Get the file.

                For Each file As StorageFile In Await dataFolder.GetFilesAsync()
                    _RC = New RSCatalogs() With { _
                    .Name = file.Name, _
                    .DTLW = "01/02/2014" _
                    }

                Next

                lvRUSAFE_FILES.DataContext = _RC

            Catch ex As Exception

            End Try
        End If

Open in new window

0
Comment
Question by:Thunder724
  • 8
  • 4
12 Comments
 
LVL 4

Author Comment

by:Thunder724
ID: 40346304
UPDATE:

I put the name for the controls in my XAML and still got the same error....

Error: BindingExpression path error: 'Name' property not found on 'Char16'. BindingExpression: Path='Name' DataItem='Char16'; target element is 'Windows.UI.Xaml.Controls.TextBlock' (Name='Name'); target property is 'Text' (type 'String')
0
 
LVL 4

Author Comment

by:Thunder724
ID: 40346334
UPDATE:
Here is my collection class.. Perhaps this is the problem.

Public Class RSCatalogs
    Implements System.ComponentModel.INotifyPropertyChanged

    Public Event PropertyChanged As System.ComponentModel.PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

    Protected Overridable Sub OnPropertyChanged(ByVal propertyName As String)
        RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs(propertyName))
    End Sub

    Private m_Name As String
    Private m_DTLW As String

    Public Property Name() As String
        Get
            Return m_Name
        End Get
        Set(value As String)
            m_Name = value
        End Set
    End Property

    Public Property DTLW() As String
        Get
            Return m_DTLW
        End Get
        Set(value As String)
            m_DTLW = value
        End Set
    End Property


End Class

Open in new window

0
 
LVL 27

Expert Comment

by:MikeToole
ID: 40347452
You've set the DataContext on the ListView twice, once in code-behind and the second time, in xaml, to a String object, rather than to an instance of your ViewModel class:
                  DataContext="RSCatalogs"
That's why it can't find the Name property on the Char16 object.

Remove the xaml setting of the DataContext. All you need is:
ItemsSource="{Binding RSCatalogs}"
0
 
LVL 4

Author Comment

by:Thunder724
ID: 40347506
Nope, I get nothing back. Below is the Error Output....

Error: BindingExpression path error: 'RSCatalogs' property not found on 'RuSafeWP.RSCatalogs, RuSafeWP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. BindingExpression: Path='RSCatalogs' DataItem='RuSafeWP.RSCatalogs, RuSafeWP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; target element is 'Windows.UI.Xaml.Controls.ListView' (Name='lvRUSAFE_FILES'); target property is 'ItemsSource' (type 'Object')

Open in new window

0
 
LVL 27

Expert Comment

by:MikeToole
ID: 40347633
OK, it's an improvement on binding to the string :-)
This is now saying that it can't find an RSCatalogs property on the RSCatalogs object instance
- Which makes sense, RScatalogs is set as the DataContext in code behind.
Switch back to ...
ItemsSource="{Binding}"
That should do the trick.
0
 
LVL 4

Author Comment

by:Thunder724
ID: 40347640
OK I got no Error outputs; but no data showing up either.
I put a message box in the code behind to make sure that file.name was returned.  There is one file so far.  Do you think there maybe something wrong with my object class _RC?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 4

Author Comment

by:Thunder724
ID: 40350432
Update:
I can see that the _RC class has data contained within it; so at least I know that the class seems to be working; just don't understand why i'm not seeing anything on the pages listview.
0
 
LVL 27

Accepted Solution

by:
MikeToole earned 500 total points
ID: 40350678
I've been approaching this bit-by-bit, looking for obvious errors - which is the nature of this site.
So here's the next one, where is the collection property that you're binding to?
RSCatalogs is a single instance of something - to drive the list you need a collection property returning either a List<MyInstanceClass> or an ObservableCollection<MyInstanceClass>
I don't see that anywhere.
0
 
LVL 4

Author Comment

by:Thunder724
ID: 40350687
Yes you are correct.  I'm not sure how to implement that; i'm thinking that is my problem too.
0
 
LVL 4

Author Comment

by:Thunder724
ID: 40350789
I got it to work.
Thanks you so much for you help.
I created a collection and bound the context to it.
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 40351089
Have separate classes for the Instance and collection. In the iteration ...
                For Each file As StorageFile In Await dataFolder.GetFilesAsync()
... add each instance to the List<MyClass> in the collection class.
Bind the Listbox to the collection class instance
0
 
LVL 4

Author Comment

by:Thunder724
ID: 40351897
Yup, that's what I did.
Thanks very much again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 61
Host asp.net pages 5 25
Entity Framework 7 30
VB.Net - Windows UserName index and length error 4 20
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now