Solved

XAML DATA BINDING LISTVIEW PROBLEM

Posted on 2014-09-26
12
296 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Author Comment

by:Thunder724
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Yup, that's what I did.
Thanks very much again.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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