locked
Issue with Data Binding and can’t figure out what is wrong. RRS feed

  • Question

  • All,

    I have tried everything to get this working. I have read and look and at a lot of resources.  Below is my code. It would be great if someone can point me to the right direction.

    [Windows::UI::Xaml::Data::Bindable]

           public ref class VideoData sealed {

           public:

                  VideoData(Platform::String^ videopath) {

                         VideoPath = videopath;

                  }

                  property Platform::String^ VideoPath;

           };

    void Eular_Layout::TrainingPage::Click_Locker(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)

    {

           auto videoinformation = ref new Vector<VideoData^>;

          

           videoinformation->Append(ref new VideoData(L"true"));

       

           DataContext = videoinformation;

    }

    <TextBlock FontSize="20" Text="{Binding VideoPath}" />

    This is the error I get.

    Error: BindingExpression path error: 'VideoPath' property not found on 'Windows.Foundation.Collections.IObservableVector`1<Eular_Layout.VideoData>'. BindingExpression: Path='VideoPath' DataItem='Windows.Foundation.Collections.IObservableVector`1<Eular_Layout.VideoData>'; target element is 'Windows.UI.Xaml.Controls.TextBlock' (Name='null'); target property is 'Text' (type 'String')

    Thanks,

    Grim


    Friday, February 7, 2014 12:23 AM

Answers

  • the datacontext of the textbox is that vector of VideoData; that isnt a single object but a list.

    your binding needs a single instance of VideoData as DataContext;

    to fix it:

    DataContext = ref new VideoData(L"true"));

    or in xaml use an ItemsControl / listview / gridview to show the whole list


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by A.B.P.Lambert Friday, February 7, 2014 1:49 PM
    Friday, February 7, 2014 10:24 AM

All replies

  • You are binding a collection of VideoData objects to your TextBlock rather than a single VideoData object. The TextBlock is not a collection control and can only take a single object. It is looking for the VideoPath object on the collection itself, which does not define VideoPath.

    It's not clear what you are trying to do here, but you either need to bind a collection of objects to an ItemsControl or a single object to a single control.

    --Rob

    Friday, February 7, 2014 3:06 AM
    Moderator
  • Could you provide an example or a little more detail?

    Thanks,

    Grim

    Friday, February 7, 2014 10:16 AM
  • the datacontext of the textbox is that vector of VideoData; that isnt a single object but a list.

    your binding needs a single instance of VideoData as DataContext;

    to fix it:

    DataContext = ref new VideoData(L"true"));

    or in xaml use an ItemsControl / listview / gridview to show the whole list


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by A.B.P.Lambert Friday, February 7, 2014 1:49 PM
    Friday, February 7, 2014 10:24 AM
  • Dave,

    Thanks so much for your help!!!

    Grim

    Friday, February 7, 2014 1:50 PM