我想創建一個WPF-Form,在TabItem內有一個TabControl,用于Checklist內的每個Category。
在每個TabItem里面是一個CheckBox的串列,每個ChecklistItem都有名字。
這是實際的資料結構:
public class Checklist
{
public int ChecklistId { get; set; }
public IEnumerable<Category> Categories { get; set; }
}
public class Category
{
public string CategoryName { get; set; }
public IEnumerable<ChecklistItem> ChecklistItems { get; set; }
}
public class ChecklistItempublic int ItemId { get; set; }
public string ItemName { get; set; }
public bool ItemChecked { get; set; }
我如何為其創建XAML?
uj5u.com熱心網友回復:
你可以使用一個ItemContainerStyle來設定標簽標題為CategoryName,并使用一個資料模板作為標簽內容的ContentTemplate。該內容模板使用一個ItemsControl來顯示ChecklistItem的串列,使用另一個包含CheckBox的資料模板來系結屬性。
<TabControl ItemsSource="{系結Checklist.Categories}">
<TabControl.ItemContainerStyle>/span>
<Style TargetType="{x: Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">。
< Setter Property="Header" Value="{Binding CategoryName}" />
</Style>>
</TabControl.ItemContainerStyle>
<TabControl.ContentTemplate>
<DataTemplate DataType="{x:Type local:Category}"/span>>
<ItemsControl ItemsSource="{Binding ChecklistItems}"/span>>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:ChecklistItem}"/span>>
< CheckBox Content="{Binding ItemName}" IsChecked="{Binding ItemChecked}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>/span>
</ItemsControl>
</DataTemplate>/span>
</TabControl.ContentTemplate>/span>
</TabControl>/span>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/312722.html
標籤:
