c# - 如何将现代标签链接 float 到左侧?

标签 c# wpf user-controls modern-ui

我已经搜索了如何将我的项目的现代选项卡(布局为列表)链接 float 到左侧,不幸的是没有找到结果:/ 请问大家有什么想法吗?

enter image description here

最佳答案

水平对齐被硬编码为右对齐。您需要替换控件模板:

<ControlTemplate TargetType="controls:ModernTab">
                    <Grid>
                        <!-- link list -->
                        <ListBox x:Name="LinkList" ItemsSource="{TemplateBinding Links}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="{DynamicResource HeaderMargin}"
                                 ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                                 ScrollViewer.VerticalScrollBarVisibility="Hidden"
                                 ScrollViewer.CanContentScroll="False"
                                 ScrollViewer.PanningMode="Both">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                                    <Setter Property="FontFamily" Value="Segoe UI" />
                                    <Setter Property="Foreground" Value="{DynamicResource MenuText}" />
                                    <Setter Property="FontSize" Value="15"/>
                                    <Setter Property="FontWeight" Value="Bold" />
                                    <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />
                                    <Setter Property="Foreground" Value="{DynamicResource MenuText}" />
                                    <Setter Property="Margin" Value="12,0,0,0" />
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                                <ContentPresenter x:Name="Presenter"
                                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsMouseOver" Value="true">
                                                        <Setter Property="Foreground" Value="{DynamicResource MenuTextHover}"/>
                                                    </Trigger>
                                                    <Trigger Property="IsSelected" Value="true">
                                                        <Setter Property="Foreground" Value="{DynamicResource MenuTextSelected}"/>
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.ItemContainerStyle>

                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>

                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding DisplayName, Converter={StaticResource ToUpperConverter}}" />
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>

                        <!-- content -->
                        <controls:ModernFrame Source="{Binding SelectedSource, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" ContentLoader="{TemplateBinding ContentLoader}" />
                    </Grid>
                </ControlTemplate>

关于c# - 如何将现代标签链接 float 到左侧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32070679/

相关文章:

c# - 自定义 Serilog 接收器无法使用 AppSettings 工作

c# - 根据TextWrapping 属性获取TextBlock 的行数?

wpf - AvalonDock 文档 View 内容在 float 窗口后消失

c# - 如何设计一个 WPF 依赖属性来支持图像路径?

wpf - 使用 XAML 进行面包屑导航控制

c# - 组合框的 WPF 不同 ItemsSource

c# - CLR 编译器优化示例

c# - 如果 IsEditable 和 IsReadOnly 为真,如何使 WPF ComboBox 键盘文本搜索正常工作?

c# - 只读依赖属性更新但首次使用时不起作用

c# - 从 ObservableCollection 实现 ListCollectionView