WPF TreeView:如何使控件相对于每个 TreeViewItem 对齐,但仍然获得标题文本的缩进效果?

2024-03-06

这是我想要实现的目标的直观想法:

我希望左侧和右侧的所有按钮都垂直对齐,无论 TreeViewItem 位于树中的哪个位置。我在实现这种效果时遇到了困难,同时也让标题以典型的嵌套方式缩进。

我最近的尝试涉及修改 TreeViewItem 模板;将按钮放在跨越主网格中所有列的 DockPanel 中(停靠在左侧或右侧),将扩展器和标题放在中间列中,并使 ItemsPresenter (ItemsHost) 跨越下一行上的所有列。这使得一切对齐,包括标题内容。

这是我目前的 TreeViewItem 样式的简化版本:

<Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
    <Setter Property="Focusable" Value="False"/>
    <Setter Property="Width" Value="16"/>
    <Setter Property="Height" Value="16"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ToggleButton}">
                <Border Background="Transparent" Height="16" Padding="5,5,5,5" Width="16">
                    <Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="{StaticResource TreeViewItem.TreeArrow.Static.Fill}" Stroke="{StaticResource TreeViewItem.TreeArrow.Static.Stroke}">
                        <Path.RenderTransform>
                            <RotateTransform Angle="135" CenterY="3" CenterX="3"/>
                        </Path.RenderTransform>
                    </Path>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter Property="RenderTransform" TargetName="ExpandPath">
                            <Setter.Value>
                                <RotateTransform Angle="180" CenterY="3" CenterX="3"/>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Fill}"/>
                        <Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Stroke}"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Stroke}"/>
                        <Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Fill}"/>
                    </Trigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsMouseOver" Value="True"/>
                            <Condition Property="IsChecked" Value="True"/>
                        </MultiTrigger.Conditions>
                        <Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Stroke}"/>
                        <Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Fill}"/>
                    </MultiTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<HierarchicalDataTemplate x:Key="HeaderTemplate" DataType="{x:Type models:Entity}" ItemsSource="{Binding Path=Entities}">
    <Label VerticalAlignment="Center">test</Label>
</HierarchicalDataTemplate>

<Style TargetType="{x:Type TreeViewItem}">
    <Setter Property="HeaderTemplate" Value="{StaticResource HeaderTemplate}"></Setter>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
    <Setter Property="HorizontalAlignment" Value="Left"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TreeViewItem}">
                <Grid HorizontalAlignment="Left" Width="300">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                        <ColumnDefinition Width="30"></ColumnDefinition>
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>

                    <DockPanel Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" Margin="1,0,0,0">
                        <Button
                            DockPanel.Dock="Left"/>

                        <Button
                            DockPanel.Dock="Left"/>

                        <Button
                            DockPanel.Dock="Left"
                        Margin="0"/>

                        <Button
                            DockPanel.Dock="Right"
                            HorizontalAlignment="Right"/>

                        <Button
                            DockPanel.Dock="Right"
                            HorizontalAlignment="Right"/>

                        <Button
                            DockPanel.Dock="Right"
                            HorizontalAlignment="Right"/>
                    </DockPanel>

                    <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="0" Margin="25,0,0,0">
                        <ToggleButton x:Name="Expander" ClickMode="Press" Margin="15,0,0,0" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ExpandCollapseToggleStyle}"/>

                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                            <ContentPresenter x:Name="PART_Header"  ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Border>

                    </StackPanel>

                    <ItemsPresenter x:Name="ItemsHost" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Width="305"/>
                </Grid>

                <ControlTemplate.Triggers>
                    <Trigger Property="IsExpanded" Value="false">
                        <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                    </Trigger>
                    <Trigger Property="HasItems" Value="false">
                        <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                    </Trigger>
                    <Trigger Property="IsSelected" Value="true">
                        <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                    </Trigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsSelected" Value="true"/>
                            <Condition Property="IsSelectionActive" Value="false"/>
                        </MultiTrigger.Conditions>
                        <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}}"/>
                    </MultiTrigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

如何让标题像图片中那样嵌套,同时保持停靠按钮的对齐?


正如您现在可能已经发现的那样,这并不是一件小事。问题在于,与 ListBox 和 DataGrid 等不同,TreeView 没有行状结构。相反,它使用看起来有点像这样的分层结构:

有一个网格包围了整个控件,但对于任何给定的“行”,TreeViewItem 不会一直延伸到您要放置按钮的左侧。

因此,要实现这一点,您必须重新模板化 TreeViewItem。默认模板使用网格来放置其内容,行内容位于第 0 行,子项(如果有)位于第 1 行。重要的是,子项也放置在第 1 列中,这就是 TreeView 缩进的方式。因此,第一步是在左侧额外放置 3 列,在右侧再放置 3 列,以容纳要添加到每行的六个按钮。然后,您需要更改每个级别的 ItemsPresenter 的 Grid.Column 和 Grid.ColumnSpan,以便它占据整个控件的宽度。

当然,现在的问题是您丢失了缩进,因此您必须向网格中添加另一列才能将其重新添加回来。要为任何给定级别正确进行缩进,您需要知道它的父级,以前是布局本身固有的,但现在已被删除。有几种解决方案,但最简单的 IMO 是使用附加属性,我将其称为TreeViewItemHelper.Indent。对于 TreeView 中的每个 ItemsPresenter,您需要计算用于当前级别以下所有子项的缩进:

<ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="10" Grid.Column="0" Grid.Row="1"
    local:TreeViewItemHelper.Indent="{Binding Path=(local:TreeViewItemHelper.Indent), Mode=OneWay, RelativeSource={RelativeSource AncestorType=ItemsPresenter}, Converter={StaticResource IndentConverter}}" />

请注意,我实际上并没有在此处使用任何值,只是通过绑定每个值来计算它应该是什么TreeViewItemHelper.Indent到上一级别中的一个并通过转换器运行它,该转换器仅添加固定数量(即用于展开树节点的 ToggleButtons 的宽度):

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    return new GridLength(((GridLength)value).Value + IndentSize);
}

最后,您需要在某处实际应用缩进。我们已经在网格中为其创建了一列,因此我们只需向该列添加一个虚拟控件,并将其宽度绑定到它所在的任何 ItemsPresenter 的缩进级别:

<Rectangle Grid.Column="3" Width="{Binding Path=(local:TreeViewItemHelper.Indent).Value, Mode=OneWay, RelativeSource={RelativeSource AncestorType=ItemsPresenter}}" Fill="Transparent"/>

将所有这些添加在一起,摇匀,这就是重新模板化 TreeViewItem 并为其分配样式的 XAML 的样子:

<local:IndentConverter x:Key="IndentConverter" />

<ControlTemplate x:Key="TreeViewItemControlTemplate1" TargetType="{x:Type TreeViewItem}">
    <Grid x:Name="tvGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <!--<ColumnDefinition Width="0"/>-->
            <ColumnDefinition MinWidth="19" Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <!-- Left buttons -->
        <Button Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2" />
        <Button Grid.Column="1" Width="12" Height="12" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2" />
        <Button Grid.Column="2" Width="12" Height="12" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2" />

        <Rectangle Grid.Column="3" Width="{Binding Path=(local:TreeViewItemHelper.Indent).Value, Mode=OneWay, RelativeSource={RelativeSource AncestorType=ItemsPresenter}}" Fill="Transparent"/>

        <ToggleButton x:Name="Expander" Grid.Column="4" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}">
            <ToggleButton.Style>
                <Style TargetType="{x:Type ToggleButton}">
                    <Setter Property="Focusable" Value="False"/>
                    <Setter Property="Width" Value="16"/>
                    <Setter Property="Height" Value="16"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                <Border Background="Transparent" Height="16" Padding="5" Width="16">
                                    <Path x:Name="ExpandPath" Data="M0,0 L0,6 L6,0 z" Fill="White" Stroke="#FF818181">
                                        <Path.RenderTransform>
                                            <RotateTransform Angle="135" CenterY="3" CenterX="3"/>
                                        </Path.RenderTransform>
                                    </Path>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsChecked" Value="True">
                                        <Setter Property="RenderTransform" TargetName="ExpandPath">
                                            <Setter.Value>
                                                <RotateTransform Angle="180" CenterY="3" CenterX="3"/>
                                            </Setter.Value>
                                        </Setter>
                                        <Setter Property="Fill" TargetName="ExpandPath" Value="#FF595959"/>
                                        <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF262626"/>
                                    </Trigger>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF27C7F7"/>
                                        <Setter Property="Fill" TargetName="ExpandPath" Value="#FFCCEEFB"/>
                                    </Trigger>
                                    <MultiTrigger>
                                        <MultiTrigger.Conditions>
                                            <Condition Property="IsMouseOver" Value="True"/>
                                            <Condition Property="IsChecked" Value="True"/>
                                        </MultiTrigger.Conditions>
                                        <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF1CC4F7"/>
                                        <Setter Property="Fill" TargetName="ExpandPath" Value="#FF82DFFB"/>
                                    </MultiTrigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ToggleButton.Style>
        </ToggleButton>
        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="5" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
            <ContentPresenter x:Name="PART_Header" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
        </Border>

        <!-- Right buttons -->
        <Button Grid.Column="7" Width="12" Height="12" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2" />
        <Button Grid.Column="8" Width="12" Height="12" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2" />
        <Button Grid.Column="9" Width="12" Height="12" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2" />

        <ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="10" Grid.Column="0" Grid.Row="1"
            local:TreeViewItemHelper.Indent="{Binding Path=(local:TreeViewItemHelper.Indent), Mode=OneWay, RelativeSource={RelativeSource AncestorType=ItemsPresenter}, Converter={StaticResource IndentConverter}}" />
    </Grid>
    <ControlTemplate.Triggers>
        <Trigger Property="IsExpanded" Value="False">
            <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
        </Trigger>
        <Trigger Property="HasItems" Value="False">
            <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
        </Trigger>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
        </Trigger>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="IsSelected" Value="True"/>
                <Condition Property="IsSelectionActive" Value="False"/>
            </MultiTrigger.Conditions>
            <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}}"/>
        </MultiTrigger>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

    <Style TargetType="TreeViewItem">
        <Setter Property="Template" Value="{DynamicResource TreeViewItemControlTemplate1}" />
        <Setter Property="IsExpanded" Value="True" />
    </Style>

这是它使用的附加属性的类:

public static class TreeViewItemHelper
{
    public static GridLength GetIndent(DependencyObject obj)
    {
        return (GridLength)obj.GetValue(IndentProperty);
    }

    public static void SetIndent(DependencyObject obj, GridLength value)
    {
        obj.SetValue(IndentProperty, value);
    }

    // Using a DependencyProperty as the backing store for Indent.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty IndentProperty =
        DependencyProperty.RegisterAttached("Indent", typeof(GridLength), typeof(TreeViewItemHelper), new PropertyMetadata(new GridLength(0)));
}

最后是缩进转换器:

public class IndentConverter : IValueConverter
{
    private const int IndentSize = 16;  // hard-coded into the XAML template

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return new GridLength(((GridLength)value).Value + IndentSize);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return Binding.DoNothing;
    }
}

结果如下:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

WPF TreeView:如何使控件相对于每个 TreeViewItem 对齐,但仍然获得标题文本的缩进效果? 的相关文章

随机推荐

  • 如何使用 HTML5 将网络摄像头捕获的 jpg 图像/视频保存在本地硬盘中

    问题看似简单 但我找不到合适的解决方案 因为我缺乏 HTML 和 Javascript 知识 任务只是设计一个网页 其中的按钮将激活网络摄像头并将静态图像或视频 最好 存储在本地硬盘驱动器中 暂时不需要上传 下载 经过一番尝试 我可以使用
  • Intellij-idea 反向粘贴到字符串中(又名从字符串复制)?

    在 Intellij idea 中 如果您将一些文本粘贴到字符串文字中 在双引号之间 java 编辑器可以自动重新格式化粘贴的文本 即为双引号新行等放置必要的转义字符 我想做相反的事情 即当从字符串文字内部复制文本时 编辑器将干净的文本放置
  • 使用 Lambda 代理集成的 Step Functions 和 Lambda

    我编写了一堆 Lambda 函数 这些函数通过 API Gateway 作为 Rest 端点公开 我选择了 Lambda 代理集成 因为它似乎是一种简单的入门方法 现在我想通过 AWS Step Functions 将其中 2 个函数链接在
  • C# 中的隐式数组转换

    我有以下定义了隐式转换运算符的类 class A class B private A m a public B A a this m a a public static implicit operator B A a return new
  • 谷歌地图获取半径

    我在使用这个谷歌地图 javascript 代码时遇到了愚蠢的困难 我想返回在谷歌地图上生成的圆的半径 Google API 提供了代码 但我不知道把它放在哪里 我到处都试过了 这是下面的代码 我做错了什么
  • java中多级继承中构造函数调用的顺序[重复]

    这个问题在这里已经有答案了 c07 Sandwich java Order of constructor calls package c07 import com bruceeckel simpletest import java util
  • spring错误没有JdbcTemplate类型的合格bean

    我有一个正在创建的 Spring Boot 应用程序Datasource and JdbcTemplate手动在我的配置中 因为我需要解密数据源密码 我正在使用 tomcatDataSource org apache tomcat jdbc
  • PUT 请求中的 100-Continue 是什么意思?

    我在某些 PUT 请求 上传文件 中看到 Expect 100 continue 这是什么意思 应该发生的情况是 您应该发送带有以下内容的请求标头 Expect 100 continue 标头 然后 在发送标头之后 发送有效负载之前 您应该
  • Xcode Beta3 中的 CMutablePointer 和 CConstPointer 发生了什么?

    Xcode Beta3 中的 CMutablePointer 和 CConstPointer 发生了什么 在 Beta2 中成功编译的代码失败并出现错误 Use of undeclared type CMutablePointer 分别使用
  • SetConsoleCtrlHandler例程问题

    我正在用 C 编写一个控制台应用程序 我使用 SetConsoleCtrlHandler 来捕获关闭和 CTRL C 按钮 这允许我的所有线程正确停止和退出 其中一个线程执行一些需要一些时间才能完成的保存 并且我有一些代码需要在控制台 cr
  • 动态函数列表并动态调用它们

    我希望能够将各种静态方法存储在列表中 然后查找它们并动态调用它们 每个静态方法都有不同数量的参数 类型和返回值 static int X int int static string Y int int string 我想要一个可以将它们全部
  • 如何在Android中获取远程设备自定义蓝牙名称?

    我想在 Android 中检索远程蓝牙设备的自定义名称 我说的是在 设置 蓝牙 和配对设备下的手机设置中找到的名称 例如 我有一个名为 DoorControl 的远程蓝牙设备 在 设置 gt 蓝牙 gt 配对设备 下 我已将设备重命名为 C
  • 为什么以及何时创建多模块 Maven 项目?

    我有一个关于 Maven 多模块项目的一般性问题 何时以及为什么要这样做 Esko Luontola 的回答 将项目拆分为多个模块很有用 例如 这些模块需要单独部署 可能会被误解 如果您有要单独部署的模块 则情况恰恰相反 在这种情况下 您永
  • 尝试让网络错误警报显示在 iPhone 应用程序上?

    好的 我正在尝试让这个应用程序显示网络错误警报代码 我添加了 SystemConfiguration framework 框架和 Apple 的 Reachability 示例代码 这是 viewcontroller h 文件 import
  • 使用一个查询更新多行?

    我在这里发现了一些可以更新一个字段的东西 http www karlrixon co uk articles sql update multiple rows with Different values and a single sql q
  • 将空格分隔的条目拆分为 R 中的新列

    我正在编写一项输出 csv 文件的调查 在此 csv 中 我有一些以空格分隔的条目 它们代表多选问题 例如具有多个答案的问题 最后 我想将这些空格分隔的条目解析到它们自己的列中 并为它们创建标题 这样我就知道它们来自哪里 例如 我可以从此开
  • MongoDB 将两个数组内的值相乘

    我需要帮助将对象数组中的值相乘以获得输出 这是我的 JSON 1 id ObjectId 5b919a785cb288f7d5311846 nome Antonio cod produtor PR001 morada rua Rua dos
  • 强制聚合之间不变量的最佳方法?

    处理聚合之间一致性的最佳方法是什么 以 Vaughn Vernon 书中的示例为例 您有 BacklogItem 聚合和 SprintAggregate 当 BacklogItemEvent 引发时 事件处理程序会捕获它并尝试更新 Spri
  • SKLabelNode 删除前导和尾随空格 - 我怎样才能阻止它?

    我想创建一个 SKLabelNode 它应该始终具有相同的长度 对于猜词游戏 不幸的是 SKLabelNode 决定始终切断任何前导和尾随空格 文档中未描述此行为 我怎样才能避免 关闭这种行为 如果您只是想让标签对齐以便它们右对齐 那么请使
  • WPF TreeView:如何使控件相对于每个 TreeViewItem 对齐,但仍然获得标题文本的缩进效果?

    这是我想要实现的目标的直观想法 我希望左侧和右侧的所有按钮都垂直对齐 无论 TreeViewItem 位于树中的哪个位置 我在实现这种效果时遇到了困难 同时也让标题以典型的嵌套方式缩进 我最近的尝试涉及修改 TreeViewItem 模板