WinRT ItemsControl with Grid columns and rows

admin

Administrator
Staff member
I'm new to XAML. I searched about ItemsControl and I found a tutorial, which is easy to understand, but the problem is that it is not work in WinRT.

Tutorial: <a href="https://rachel53461.wordpress.com/2011/09/17/wpf-itemscontrol-example/" rel="nofollow">https://rachel53461.wordpress.com/2011/09/17/wpf-itemscontrol-example/</a>

I tried to use
Code:
TargetType
in
Code:
Style
tag, however, in runtime I got an exception.

Code:
&lt;ItemsControl ItemsSource="{Binding MyCollection}"&gt;
    &lt;!-- ItemsPanelTemplate --&gt;
    &lt;ItemsControl.ItemsPanel&gt;
        &lt;ItemsPanelTemplate&gt;
            &lt;Grid&gt;
                &lt;Grid.RowDefinitions&gt;
                    &lt;RowDefinition /&gt;
                    &lt;RowDefinition /&gt;
                    &lt;RowDefinition /&gt;
                    &lt;RowDefinition /&gt;
                    &lt;RowDefinition /&gt;
                    &lt;RowDefinition /&gt;
                &lt;/Grid.RowDefinitions&gt;
                &lt;Grid.ColumnDefinitions&gt;
                    &lt;ColumnDefinition /&gt;
                    &lt;ColumnDefinition /&gt;
                    &lt;ColumnDefinition /&gt;
                    &lt;ColumnDefinition /&gt;
                    &lt;ColumnDefinition /&gt;
                    &lt;ColumnDefinition /&gt;
                &lt;/Grid.ColumnDefinitions&gt;
            &lt;/Grid&gt;
        &lt;/ItemsPanelTemplate&gt;
    &lt;/ItemsControl.ItemsPanel&gt;

    &lt;!-- ItemContainerStyle --&gt;
    &lt;ItemsControl.ItemContainerStyle&gt;
        &lt;Style TargetType="TextBox"&gt;
            &lt;Setter Property="Grid.Column"
                Value="{Binding xIndex}" /&gt;
            &lt;Setter Property="Grid.Row"
                Value="{Binding yIndex}" /&gt;
        &lt;/Style&gt;
    &lt;/ItemsControl.ItemContainerStyle&gt;

    &lt;!-- ItemTemplate --&gt;
    &lt;ItemsControl.ItemTemplate&gt;
        &lt;DataTemplate&gt;
            &lt;TextBox  Background="{Binding color}" Text="{Binding xIndex,Mode=OneWay}" /&gt;
        &lt;/DataTemplate&gt;
    &lt;/ItemsControl.ItemTemplate&gt;
&lt;/ItemsControl&gt;