TabControl动态绑定的模板及样式定义

模板样式定义:

<TabControl ItemsSource="{Binding Items}">
    <TabControl.ContentTemplate>
        <DataTemplate>
            <ListBox
                BorderThickness="0"
                ItemsSource="{Binding Items}"
                ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Style="{StaticResource TextBlockWrapStyle}">
                            <Run Text="{Binding SortIndex}" />
                            <Run Text="{Binding Question}" />
                        </TextBlock>
                    </DataTemplate>
                </ListBox.ItemTemplate>

                <ListBox.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="{Binding SelectQuestionCommand}" Header="选择题目" />
                        <Separator />
                        <MenuItem Command="{Binding RefreshCommand}" Header="刷新" />
                    </ContextMenu>
                </ListBox.ContextMenu>
            </ListBox>
        </DataTemplate>
    </TabControl.ContentTemplate>
    <TabControl.ItemContainerStyle>
        <Style TargetType="TabItem">
            <Setter Property="Header" Value="{Binding Type}" />
            <Setter Property="Padding" Value="18,5" />
        </Style>
    </TabControl.ItemContainerStyle>
</TabControl>

 

posted @ 2022-09-06 11:10  wzwyc  阅读(442)  评论(0编辑  收藏  举报