我正在构建一个包含n列ListView的用户控件,所以我有一个列表列表:
C#:
<ListView Name="lvwLista" Grid.Row="1" SelectionMode="Single" ScrollViewer.IsDeferredScrollingEnabled="False" ItemsSource="{Binding ListItems, ElementName=ucListaCompletarControl}">
<ListView.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Path=.}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
XAML:
List<List<string>>
但我不知道如何将ALTER TABLE main_itemmaster ADD uniq int UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE main_itemmaster ADD UNIQUE KEY (tv_series_id, tv_season_number, name, uniq);
DELIMITER ;;
CREATE TRIGGER main_itemmaster_before_insert BEFORE INSERT ON main_itemmaster
FOR EACH ROW
BEGIN
SET NEW.uniq = IFNULL(NEW.tv_episode_number, 0);
END;;
CREATE TRIGGER main_itemmaster_before_update BEFORE UPDATE ON main_itemmaster
FOR EACH ROW
BEGIN
SET NEW.uniq = IFNULL(NEW.tv_episode_number, 0);
END;;
DELIMITER ;
绑定到ListView。
感谢。
答案 0 :(得分:1)
您正在访问ItemTemplate中的List<string>
,因此您可以像往常一样绑定其属性。
<ListView Name="lvwLista"
ItemsSource="{Binding ListItems, ElementName=ucListaCompletarControl}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Path=Item[0]}"/>
<Label Content="{Binding Path=Item[1]}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
或者
<ListView Name="lvwLista"
ItemsSource="{Binding ListItems, ElementName=ucListaCompletarControl}">
<ListView.ItemTemplate>
<DataTemplate>
<ListView ItemsSource="{Binding}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Label Content="{Binding}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 1 :(得分:0)
以下链接标题为; &#34;将列表列表绑定到GridView,其中包含WPF中的GridLists&#34;对你有帮助。
答案 2 :(得分:0)
谢谢大家,我的解决方案是一个只有行中的项目的字符串,并将其添加到List:
C#:
public static List<string> ListItems { get; set; }
for(...)
{
for(...)
{
var itemList = string.Empty;
itemList += item.ToString() + "\t";
}
ListItems.Add(itemList);
}
XAML:
<ListView Name="lvwLista" Grid.Row="1" SelectionMode="Single"
ScrollViewer.IsDeferredScrollingEnabled="False"
ItemsSource="{Binding ListItems, ElementName=ucListaCompletarControl}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>