我能够在WPF中创建条纹模式,但是如何在XAML中创建这样的模式?在WPF中是否有默认类似的刷子?

我有两个清单.BeamElevations<Elevation>和FloorElevations<Elevation>.如何将这些合并到Elevations<Elevation>列表中并根据他们使用Linq的Elevation进行排序?
我正在使用WPF创建大量文本DrawText,然后将它们添加到单个文本中Canvas.
我需要在每个MouseWheel事件中重绘屏幕并且我意识到性能有点慢,所以我测量了创建对象的时间并且它不到1毫秒!
那可能是什么问题呢?很久以前,我想我读到的地方实际上是Rendering花费时间,而不是创建和添加视觉效果.
这是我用来创建文本对象的代码,我只包含了基本部分:
public class ColumnIdsInPlan : UIElement
{
private readonly VisualCollection _visuals;
public ColumnIdsInPlan(BaseWorkspace space)
{
_visuals = new VisualCollection(this);
foreach (var column in Building.ModelColumnsInTheElevation)
{
var drawingVisual = new DrawingVisual();
using (var dc = drawingVisual.RenderOpen())
{
var text = "C" + Convert.ToString(column.GroupId);
var ft = new FormattedText(text, cultureinfo, flowdirection,
typeface, columntextsize, columntextcolor,
null, TextFormattingMode.Display)
{
TextAlignment = TextAlignment.Left
};
// Apply Transforms
var st = new ScaleTransform(1 / scale, …Run Code Online (Sandbox Code Playgroud) 我有两个列表如下,我怎么能说他们有相同的元素.订单并不重要.
var list1 = new List<int> {1,2,3};
var list2 = new List<int> {2,1,3};
Run Code Online (Sandbox Code Playgroud)
我怎么能说这些是平等的?我应该编写自己的方法还是有内置的方法?
在这里,我们有一个Grid带有Button. 当用户单击按钮时,会执行 Utility 类中的一个方法,该方法强制应用程序接收对 Grid 的单击。代码流必须在此处停止,并且在用户单击Grid.
我在这里之前也有过类似的问题:
在那个问题中,我使用 async/await 得到了一个有效的答案,但是由于我要将它用作 API 的一部分,因此我不想使用 async/await,因为消费者将不得不用我不想要的异步。
我如何编写Utility.PickPoint(Grid grid)方法来实现这个目标?
我看到这可能会有所帮助,但老实说,我并没有完全理解它适用于这里:
将其视为控制台应用程序中的 Console.ReadKey() 方法。当我们调用这个方法时,代码流停止,直到我们输入某个值。直到我们输入一些东西,调试器才会继续。我想要 PickPoint() 方法的确切行为。代码流将停止,直到用户单击网格。
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid x:Name="View" Background="Green"/>
<Button Grid.Row="1" Content="Pick" Click="ButtonBase_OnClick"/>
</Grid>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
// …Run Code Online (Sandbox Code Playgroud) 我正试图将两个<Run>s 绑定在一个内部TextBlock,如下面的代码片段所示.但我得到了一个XamlParseException.
基本上我正在尝试实现这种格式:
CodeNum: LongDescription
如果下面的代码注定要失败,我还有其他选择吗?
<TextBlock>
<Run FontWeight="Bold" Text="{Binding CodeNum}"/>
<Run FontWeight="Bold" Text=": "/>
<Run Text="{Binding LongDescription}"/>
</TextBlock>
Run Code Online (Sandbox Code Playgroud) 如何使用Linq和找到值列表中的第二个最大数字C#?
例如,我有这个列表:
List<double> ListOfNums = new List<double> {1, 5, 7, -1, 4, 8};
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以获得列表中第二个最大值7?
我有一个Column课程如下:
public class Column
{
public int LocId { get; set; }
public int SecId { get; set; }
public double StartElevation { get; set; }
public double EndElevation { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
以及Column对象列表:
List<Column> Columns = new List<Column>();
Run Code Online (Sandbox Code Playgroud)
例如:
Columns:
{
Column1: { LocId = 1 , SecId = 1, StartElevation = 0, EndElevation = 160 }
Column2: { LocId = 1 , SecId = 1, StartElevation = 160, EndElevation = 320 }
Column3: …Run Code Online (Sandbox Code Playgroud) 我正在使用Visual Layer DrawText进行绘制FormattedText.现在我使用下面的代码来定义格式化的文本,我可以设置TextAlignment为Center.但是VerticalAlignment呢?如下图所示,文本中心不在中心点,此处显示红点.
我正在定义的部分FormattedText:
var ft = new FormattedText("A",
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"),
36, Brushes.Yellow);
ft.TextAlignment = TextAlignment.Center;
Run Code Online (Sandbox Code Playgroud)
我正在绘制文本的部分:
var centerpoint = new Point(0,0);
dc.DrawText(ft, centerpoint);
Run Code Online (Sandbox Code Playgroud)
这是最终结果:

我希望文本的中间位于圆圈的中心.
我的XAML很长很难维护.我想知道是否有办法做重构之类的事情?
这是一个简单的例子:
<Window x:Class="RefactorXAML.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<Button>New</Button>
<Button>Open</Button>
</StackPanel>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
我怎样才能重构该Stackpanel部分并写出这样的内容?
<Window x:Class="RefactorXAML.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
// Refactored Markup
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud) c# ×9
wpf ×6
linq ×4
xaml ×3
drawtext ×2
list ×2
async-await ×1
events ×1
hatchstyle ×1
performance ×1
textblock ×1