您好我正在尝试在ListView中创建3列。
我读过这篇文章,但我想在C#中以编程方式设置每列中的数据:
how to display data in rows and columns XAML windows 8
例如,我想要艺术家姓名,歌曲名称和艺术家。
答案 0 :(得分:7)
假设你有这样的东西存储你的数据:
public class SongDetails
{
public string ArtistName {get; set;}
public string SongName {get; set;}
public string Artist {get; set;}
}
定义了一个带有DataTemplate的ListView(如你提供的链接),只需给你的ListView一个名字:
<ListView Name="ListViewSongs">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="500" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Artist}" />
<TextBlock Grid.Column="1" Text="{Binding ArtistName}" />
<TextBlock Grid.Column="2" Text="{Binding SongName}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
然后,从代码隐藏,它只是一个案例:
var songDetails = new[]
{
new SongDetails {Artist = "a1", ArtistName = "a2", SongName = "a3"},
new SongDetails {Artist = "b1", ArtistName = "b2", SongName = "b3"}
};
ListViewSongs.ItemsSource = songDetails;
答案 1 :(得分:5)
如果您不想硬编码项目/网格的宽度(响应式设计),则改进Seb Boulet's answer的XAML:
library(shiny)
library(ggplot2)
library(dplyr)
shinyServer(function(input, output) {
dataset <- reactive({
iris %>%
filter(Species==input$species)
#%>% mutate(yvar=lead(input$y, paste0(input$offset)))
})
output$plot <- renderPlot({
dataset<-dataset()
p <- ggplot(dataset, aes_string(x=input$x,
#y=yvar)
y=input$y
)) +
geom_point()
print(p)
}, height=500)
})
相关主题:How to get a ListBox ItemTemplate to stretch horizontally the full width of the ListBox?