Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XAML DATA BINDING LISTVIEW PROBLEM

Posted on 2014-09-26
12
Medium Priority
?
329 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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
 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

782 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