locked
xaml binding List to IObservableMap

    Question

  • I set DataContext to MyDataContext class instance, there are two propertis - VectorProp and MapProp.

    XAML binding works good for List but not for Map. It seems like the Map cannot be iterated through.

    Don't you know why? Thanks

    Antonin

    [Windows::UI::Xaml::Data::Bindable]	
    public ref class MyDataContext sealed 
    {
    public:
    	MyDataContext()
    	{
    		m_vectorProp = ref new Platform::Collections::Vector<Platform::String^>();
    		m_vectorProp->Append( L"item1" );
    
    		m_mapProp = ref new Platform::Collections::Map<Platform::String^, Platform::String^>();
    		m_mapProp->Insert(L"Key1", L"Val1");
    	}
    
    	property IObservableVector<Platform::String^>^ VectorProp
    	{
    		IObservableVector<Platform::String^>^ get() { return m_vectorProp; }
    	}
    	property IObservableMap<Platform::String^, Platform::String^>^ MapProp
    	{
    		IObservableMap<Platform::String^, Platform::String^>^ get() { return m_mapProp; }
    	}
    
    private:
    	Platform::Collections::Vector<Platform::String^>^ m_vectorProp;
    	Platform::Collections::Map<Platform::String^, Platform::String^>^ m_mapProp;
    };
    
    
    
    
     <StackPanel>
            <ListBox ItemsSource="{Binding Path=VectorProp}" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                             <TextBlock Text="helloList" />
                         </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
    
            </ListBox>
    
            <ListBox ItemsSource="{Binding Path=MapProp}" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock Text="helloMap" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
    
            </ListBox>
        </StackPanel>


    Thursday, September 27, 2012 8:30 AM

Answers

  • Hello,

    IMap is derrived from IIterable<IKeyValuePair>

    IVector is derived from IIterable<T>

    IIterable<T> returns a single value that can be bound to the control.

    IIterable<IKeyValuePair> returns an object that represents a pair of objects that cannot be bound to the control.

    I hope this helps,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, October 2, 2012 10:00 PM
    Moderator

All replies

  • Hello,

     

    Thanks for your feedback, I will involve more experts to investigate it.

     

    Best regards,

    Jesse


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

    Monday, October 1, 2012 6:16 AM
  • Hello,

    IMap is derrived from IIterable<IKeyValuePair>

    IVector is derived from IIterable<T>

    IIterable<T> returns a single value that can be bound to the control.

    IIterable<IKeyValuePair> returns an object that represents a pair of objects that cannot be bound to the control.

    I hope this helps,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, October 2, 2012 10:00 PM
    Moderator
  • Thanks for your help,

    but I think, this IS possible for "Windows-WPF" and Silverlight by specifying  "{Binding Key}"  or "{Binding Value}" inside <DataTemplate> section.

    Or, am I wrong? 

    Does it mean, binding  IIterable<IKeyValuePair> to ListBox will not be possible for WinRT ?

    Cheers Antonin

    Sunday, October 7, 2012 4:22 PM