Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XAML DATA BINDING LISTVIEW PROBLEM

Posted on 2014-09-26
12
Medium Priority
?
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 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