locked
How to create item class for Listbox to bind item collection with C++ in Windows8.

    Question

  • hi MSFT,

    How to create item class for Listbox to bind item collection with C++ in Windows8?

    public ref class Employee  : Windows::UI::Xaml::Data::INotifyPropertyChanged 
        { 
        public: 
    		Employee(){}; 
    		~Employee(){}; 
            event PropertyChangedEventHandler^ PropertyChanged; 
            property String^ Name 
            { 
                String^ get() 
                {  
                    return _name; 
                } 
                void set(String^ value) 
                { 
                    _name = value; 
                    RaisePropertyChanged("Name"); 
                } 
            } 
            property String^ Organization 
            { 
                String^ get() 
                {  
                    return _organization; 
                } 
                void set(String^ value) 
                { 
                    _organization = value; 
                    RaisePropertyChanged("Organization"); 
                } 
            } 
     
        protected: 
            void RaisePropertyChanged(String^ name)
    		{
    			if (PropertyChanged != nullptr)
    			{
    				PropertyChanged(this, ref new PropertyChangedEventArgs(name));
    			}
    		}
     
        private: 
            String^ _name; 
            String^ _organization; 
     
        }; 


    <ListBox  x:Name="ende_ff_ende_listbox" Grid.Row="1" Margin="0,10,50,25"   Background="Transparent"  ItemTemplate="{StaticResource  ende_listboxTemplate}"/>

    <DataTemplate x:Key="ende_listboxTemplate"  >
                <Grid x:Name="ende_item_grid">
                    <TextBlock x:Name="ende_text_block" Text="{Binding  Path=Name}" Margin="0,0,0,0" TextAlignment="Center" TextWrapping="Wrap" Tapped="ende_encrypted_item_tapped" RightTapped="ende_encrypted_item_right_tapped"></TextBlock>
                    <!--<ProgressRing   x:Name="ende_progress_ring"  Margin="0,0,0,0"  IsActive="True"></ProgressRing>-->
                    <ProgressBar Minimum="0" Maximum="100" x:Name="ende_progress_bar" Margin="0,0,0,0" Visibility="Collapsed" ></ProgressBar>
                </Grid>
            </DataTemplate> 

    I could add such binding as following but it doesn't work.

             ende_Collection = ref new Vector<Object^>();
    	Employee^ employee = ref new Employee();
    	employee->Name = "test name";
    	ende_Collection->Append(employee);
    	ende_Collection->Append(employee);
    	ende_ff_ende_listbox->DataContext = employee;
    	ende_ff_ende_listbox->ItemsSource = ende_Collection;

    I can not pass "test name" to text block's text (ende_text_block->Text).

    how to do that?

    Thanks,

    Kevin.

    Thursday, March 22, 2012 11:49 AM

All replies

  • Hello,

    I think this is binging's problem, you can change Text="{Binding  Path=Name}" as Text="{Binding Name}"

    On the other hand, you can follow this sample code

    http://code.msdn.microsoft.com/windowsapps/Data-Binding-7b1d67b5

    I hope these information can help you to solve this problem.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 23, 2012 9:38 AM
  • hi Jesse,

    Thanks a lot for your reply.

    But there is still a problem: i can not the property "[Windows::UI::Xaml::Data::Bindable] " in Developer Preview.

    because my project is based on Developer Preview.

    Thanks,

    Kevin.

    Tuesday, March 27, 2012 1:12 AM
  • Hi Kevin,

    We would strongly recommend to update your system to Windows 8 customer preview.

    The front sample also base on the customer preview.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Jesse Jiang Thursday, March 29, 2012 3:04 AM
    Tuesday, March 27, 2012 2:04 AM
  • Thanks a lot Jesse.
    Wednesday, March 28, 2012 1:28 AM