我ObservableCollection<string>在 viewModel 中有一個,并且我已將其設定為ItemsControl.
代碼
<ItemsControl ItemsSource="{Binding NameofCollection}">
</ItemsControl>
它正常顯示,1 列,集合中的所有專案都出現在新行中。
現在,我想在當前列旁邊有一個新列,它應該為所有專案顯示一個固定的字串(例如“yes”)。
因此,如果集合中有 5 個元素,則新列應包含 5 個單元格,每個單元格都包含一個固定字串“yes”。
努力自己實作它。
uj5u.com熱心網友回復:
你可以這樣做:
<ItemsControl ItemsSource="{Binding NameofCollection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding}"/>
<TextBlock Grid.Column="1" Text="yes"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/449537.html
