.net-4.5 相关问题

Microsoft .NET Framework 4.5版。用于与.NET Framework 4.5特别相关的问题。有关.NET Framework的问题,请使用.net标记。

“双”原子的 Volatile.Read / Volatile.Write 是吗?

MSDN 指出: 其他类型(包括 long、ulong、double 和decimal)以及用户定义类型的读取和写入不需要是原子的。 C# 7.0 规范草案 - 变量 - 9.6 Atom...

回答 2 投票 0

Volatile.Read / Volatile.Write 是否为“双”原子?

MSDN 指出 long、ulong、double 和decimal 以及用户定义的类型不保证是原子的 5.5 变量引用的原子性 Will Volatile.Write方法(Double%,D...

回答 2 投票 0

C# Mongo 查询 $maxTimeMS 的计数

我正在尝试实现 $maxTimeMS,同时尝试从 C# MongoDB 获取过滤器的计数。我不知道该怎么做。 我的 C# 代码: var doc = MongoDB.Bson.Serialization.

回答 1 投票 0

线程或任务(停止挂起的单行代码)

线程/任务和异步处理新手... 我有一个尝试获取文件的进程,但是,如果该文件受密码保护,则对 GetDocument 的调用永远不会返回,并挂起服务....

回答 2 投票 0

安装 .NET 4.5 后无法构建单元测试项目

我有一个 .NET 4.0 中的 WPF 解决方案,其中包括一个单元测试项目,该项目测试 ViewModel 中使用的不同命令。一切都工作正常,但后来我安装了.NET 4.5 和 VS2012....

回答 1 投票 0

在具有不同屏幕分辨率和/或比例的显示器之间移动窗口时 WPF 中的视频渲染问题

我有一个 winforms 应用程序(嗯,它是一个在 Outlook 中运行的 VSTO Outlook 插件),我在其中使用工具栏,并在该工具栏中通过使用

回答 1 投票 0

在不同任务中同时使用 ClientWebSocket SendAsync 和 ReceiveAsync 方法时出现意外行为 (.Net Framework)

我的自定义 WebSocket 客户端(使用 System.Net.WebSockets 库)运行得很好。在内部,库有 2 个独立的任务:第一个任务是将命令发送到 Web 套接字服务器,例如...

回答 1 投票 0

创建自定义语音气泡工具提示,根据每种情况调整/放置其箭头/指针

我有一个 WPF 语音气泡工具提示,运行良好。 <Setter Property="OverridesDefaultStyle" ...</desc> <question vote="0"> <p>我有一个 WPF 语音气泡工具提示,运行良好。</p> <pre><code>&lt;Style x:Key=&#34;{x:Type ToolTip}&#34; TargetType=&#34;ToolTip&#34;&gt; &lt;Setter Property=&#34;OverridesDefaultStyle&#34; Value=&#34;true&#34; /&gt; &lt;Setter Property=&#34;HorizontalOffset&#34; Value=&#34;1&#34; /&gt; &lt;Setter Property=&#34;VerticalOffset&#34; Value=&#34;1&#34; /&gt; &lt;Setter Property=&#34;Background&#34; Value=&#34;White&#34; /&gt; &lt;Setter Property=&#34;Foreground&#34; Value=&#34;Black&#34; /&gt; &lt;Setter Property=&#34;FontSize&#34; Value=&#34;12&#34; /&gt; &lt;Setter Property=&#34;FontFamily&#34; Value=&#34;Segoe UI&#34; /&gt; &lt;Setter Property=&#34;DataContext&#34; Value=&#34;{Binding Path=PlacementTarget.DataContext, RelativeSource={x:Static RelativeSource.Self}}&#34;/&gt; &lt;Setter Property=&#34;Template&#34;&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType=&#34;ToolTip&#34;&gt; &lt;Canvas Width=&#34;225&#34; Height=&#34;131&#34;&gt; &lt;Path x:Name=&#34;Container&#34; Canvas.Left=&#34;0&#34; Canvas.Top=&#34;0&#34; Margin=&#34;0&#34; Data=&#34;M8,7.41 L15.415,0 L22.83,7.41 L224,7.41 L224,130 L0,130 L0,7.41 L8,7.41&#34; Fill=&#34;{TemplateBinding Background}&#34; Stroke=&#34;Gray&#34;&gt; &lt;Path.Effect&gt; &lt;DropShadowEffect BlurRadius=&#34;10&#34; Opacity=&#34;0.5&#34; ShadowDepth=&#34;4&#34; /&gt; &lt;/Path.Effect&gt; &lt;/Path&gt; &lt;TextBlock Canvas.Left=&#34;10&#34; Canvas.Top=&#34;10&#34; Width=&#34;100&#34; Height=&#34;65&#34; Text=&#34;{TemplateBinding Content}&#34; TextWrapping=&#34;WrapWithOverflow&#34; /&gt; &lt;/Canvas&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>上述方法的问题是,无论情况如何,语音气泡工具提示(路径)的箭头/指针始终放置在相同的位置,我希望它适应情况并使用以下之一(以上样式实现箭头位于左上角,下面屏幕截图中的第一个工具提示):</p> <p><a href="https://i.stack.imgur.com/T2MdB.png" target="_blank"><img src="https://cdn.imgupio.com/i/AWkuc3RhY2suaW1ndXIuY29tL1QyTWRCLnBuZw==" alt=""/></a></p> <p>我该怎么做?可以吗?</p> </question> <answer tick="false" vote="1"> <p>这是此任务的完整代码:</p> <pre><code>using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace Decorators { public enum Position { None, Top, Bottom, RightSide, LeftSide, } public enum SpecificPosition { None, LeftOrTop = 25, Center = 50, RightOrBottom = 75, } internal class BubbleTextDecorator : Decorator { #region DependencyProperties public static readonly DependencyProperty VerticalMarginProperty = DependencyProperty.Register(&#34;VerticalMargin&#34;, typeof(double), typeof(BubbleTextDecorator), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); public double VerticalMargin { get { return (double)GetValue(VerticalMarginProperty); } set { SetValue(VerticalMarginProperty, value); } } public static readonly DependencyProperty HorizontalMarginProperty = DependencyProperty.Register(&#34;HorizontalMargin&#34;, typeof(double), typeof(BubbleTextDecorator), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); public double HorizontalMargin { get { return (double)GetValue(HorizontalMarginProperty); } set { SetValue(HorizontalMarginProperty, value); } } public static readonly DependencyProperty PointerPositionProperty = DependencyProperty.Register(&#34;PointerPosition&#34;, typeof(Position), typeof(BubbleTextDecorator), new FrameworkPropertyMetadata(Position.None, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure)); public Position PointerPosition { get { return (Position)GetValue(PointerPositionProperty); } set { SetValue(PointerPositionProperty, value); } } public static readonly DependencyProperty AlignmentPositionProperty = DependencyProperty.Register(&#34;AlignmentPosition&#34;, typeof(SpecificPosition), typeof(BubbleTextDecorator), new FrameworkPropertyMetadata(SpecificPosition.None, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure)); public SpecificPosition AlignmentPosition { get { return (SpecificPosition)GetValue(AlignmentPositionProperty); } set { SetValue(AlignmentPositionProperty, value); } } public static readonly DependencyProperty PointerHeightProperty = DependencyProperty.Register(&#34;PointerHeight&#34;, typeof(double), typeof(BubbleTextDecorator), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); public double PointerHeight { get { return (double)GetValue(PointerHeightProperty); } set { SetValue(PointerHeightProperty, value); } } public static readonly DependencyProperty PointerWidthProperty = DependencyProperty.Register(&#34;PointerWidth&#34;, typeof(double), typeof(BubbleTextDecorator), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsRender)); public double PointerWidth { get { return (double)GetValue(PointerWidthProperty); } set { SetValue(PointerWidthProperty, value); } } #endregion protected override Size ArrangeOverride(Size arrangeSize) { Size desiredSize = base.ArrangeOverride(arrangeSize); if (Child != null) { switch (PointerPosition) { case Position.Top: Child.Arrange(new Rect(new Point(0.0, PointerHeight), new Point(desiredSize.Width, desiredSize.Height))); break; case Position.Bottom: Child.Arrange(new Rect(new Point(0.0, 0.0), new Point(desiredSize.Width, desiredSize.Height - PointerHeight))); break; case Position.LeftSide: Child.Arrange(new Rect(new Point(PointerHeight, 0.0), new Point(desiredSize.Width, desiredSize.Height))); break; case Position.RightSide: Child.Arrange(new Rect(new Point(0.0, 0.0), new Point(desiredSize.Width - PointerHeight, desiredSize.Height))); break; } } return arrangeSize; } protected override Size MeasureOverride(Size constraint) { Size desiredSize = base.MeasureOverride(constraint); Size size = (PointerPosition == Position.Top || PointerPosition == Position.Bottom) ? new Size(desiredSize.Width + (HorizontalMargin * 2), desiredSize.Height + (VerticalMargin * 2) + PointerHeight) : new Size(desiredSize.Width + (HorizontalMargin * 2) + PointerHeight, desiredSize.Height + (VerticalMargin * 2)); return size; } protected override void OnRender(DrawingContext drawingContext) { Brush renderBrush = Brushes.Transparent; Pen renderPen = new Pen(Brushes.Black, 1); StreamGeometry geom = new StreamGeometry(); switch (PointerPosition) { case Position.Top: DrawTop(geom); break; case Position.Bottom: DrawBottom(geom); break; case Position.RightSide: DrawRight(geom); break; case Position.LeftSide: DrawLeft(geom); break; } // Some arbitrary drawing implements. drawingContext.DrawGeometry(renderBrush, renderPen, geom); } private void DrawLeft(StreamGeometry geom) { using (StreamGeometryContext ctx = geom.Open()) { ctx.BeginFigure( new Point(PointerHeight, 0.0), true, true); ctx.LineTo( new Point(ActualWidth, 0.0), true, false); ctx.LineTo( new Point(ActualWidth, ActualHeight), true, false); ctx.LineTo( new Point(PointerHeight, ActualHeight), true, false); ctx.LineTo( new Point(PointerHeight, (ActualHeight * (double)AlignmentPosition / 100) + (PointerWidth / 2)), true, false); ctx.LineTo( new Point(0.0, ActualHeight * (double)AlignmentPosition / 100), true, false); ctx.LineTo( new Point(PointerHeight, (ActualHeight * (double)AlignmentPosition / 100) - (PointerWidth / 2)), true, false); ctx.LineTo( new Point(PointerHeight, 0.0), true, false); } } private void DrawRight(StreamGeometry geom) { using (StreamGeometryContext ctx = geom.Open()) { ctx.BeginFigure( new Point(0.0, 0.0), true, true); ctx.LineTo( new Point(ActualWidth - PointerHeight, 0.0), true, false); ctx.LineTo( new Point(ActualWidth - PointerHeight, (ActualHeight * (double)AlignmentPosition / 100) - (PointerWidth / 2)), true, false); ctx.LineTo( new Point(ActualWidth, ActualHeight * (double)AlignmentPosition / 100), true, false); ctx.LineTo( new Point(ActualWidth - PointerHeight, (ActualHeight * (double)AlignmentPosition / 100) + (PointerWidth / 2)), true, false); ctx.LineTo( new Point(ActualWidth - PointerHeight, ActualHeight), true, false); ctx.LineTo( new Point(0.0, ActualHeight), true, false); ctx.LineTo( new Point(0.0, 0.0), true, false); } } private void DrawBottom(StreamGeometry geom) { using (StreamGeometryContext ctx = geom.Open()) { ctx.BeginFigure( new Point(0.0, 0.0), true, true); ctx.LineTo( new Point(ActualWidth, 0.0), true, false); ctx.LineTo( new Point(ActualWidth, ActualHeight - PointerHeight), true, false); ctx.LineTo( new Point((ActualWidth * (double)AlignmentPosition / 100) + (PointerWidth / 2), ActualHeight - PointerHeight), true, false); ctx.LineTo( new Point(ActualWidth * (double)AlignmentPosition / 100, ActualHeight), true, false); ctx.LineTo( new Point((ActualWidth * (double)AlignmentPosition / 100) - (PointerWidth / 2), ActualHeight - PointerHeight), true, false); ctx.LineTo( new Point(0.0, ActualHeight - PointerHeight), true, false); ctx.LineTo( new Point(0.0, 0.0), true, false); } } private void DrawTop(StreamGeometry geom) { using (StreamGeometryContext ctx = geom.Open()) { ctx.BeginFigure( new Point(0.0, PointerHeight), true, true); ctx.LineTo( new Point((ActualWidth * (double)AlignmentPosition / 100) - (PointerWidth / 2), PointerHeight), true, false); ctx.LineTo( new Point(ActualWidth * (double)AlignmentPosition / 100, 0.0), true, false); ctx.LineTo( new Point((ActualWidth * (double)AlignmentPosition / 100) + (PointerWidth / 2), PointerHeight), true, false); ctx.LineTo( new Point(ActualWidth, PointerHeight), true, false); ctx.LineTo( new Point(ActualWidth, ActualHeight), true, false); ctx.LineTo( new Point(0.0, ActualHeight), true, false); ctx.LineTo( new Point(0.0, PointerHeight), true, false); } } } } </code></pre> <p>这就是你如何使用它:</p> <pre><code>&lt;localdecorators:BubbleTextDecorator PointerHeight=&#34;10&#34; PointerWidth=&#34;20&#34; PointerPosition=&#34;LeftSide&#34; AlignmentPosition=&#34;Center&#34; VerticalMargin=&#34;30&#34; HorizontalMargin=&#34;30&#34; HorizontalAlignment=&#34;Left&#34;&gt; &lt;TextBlock Text=&#34;this&#34; HorizontalAlignment=&#34;Center&#34; VerticalAlignment=&#34;Center&#34;/&gt; &lt;/localdecorators:BubbleTextDecorator&gt; </code></pre> <p><a href="https://i.stack.imgur.com/0ycsH.png" target="_blank"><img src="https://cdn.imgupio.com/i/AWkuc3RhY2suaW1ndXIuY29tLzB5Y3NILnBuZw==" alt=""/></a></p> </answer> <answer tick="false" vote="0"> <p>目前我正在努力解决同样的问题。 您已经有解决这个问题的方法了吗?</p> <p>致以诚挚的问候</p> </answer> <answer tick="false" vote="-1"> <p>这是创建Decorator的典型案例。我曾经围绕文本制作了一个可定制的 ArrowBorder。你需要继承Decorator类。</p> <pre><code>internal class ArrowBorderDecorator : Decorator </code></pre> <p>然后你需要一些 DependencyProperties 以便于自定义。 在我的例子中,这是 <pre><code>ArrowTipToArrowTriangleBaseDistance</code></pre> 属性,这意味着箭头应该有多“尖”。在你的例子中,气泡文本箭头应该在哪里。</p> <pre><code> public static readonly DependencyProperty ArrowTipToArrowTriangleBaseDistanceProperty = DependencyProperty.Register(&#34;ArrowTipToArrowTriangleBaseDistance&#34;, typeof(double), typeof(ArrowBorderDecorator), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); public double ArrowTipToArrowTriangleBaseDistance { get { return (double)GetValue(ArrowTipToArrowTriangleBaseDistanceProperty); } set { SetValue(ArrowTipToArrowTriangleBaseDistanceProperty, value); } } </code></pre> <p>然后您需要重写 <pre><code>ArrangeOverride</code></pre>、<pre><code>MeasureOverride</code></pre> 和 <pre><code>OnRender</code></pre> 方法。前两个来自 Decorator 类,第三个来自 UIElement 类。</p> <p>这里有一个很好的<a href="https://stackoverflow.com/questions/66818340/measureoverride-and-arrangeoverride-what-is-really-availablesize-desiredsize">链接</a>来理解前两个。 在 <pre><code>OnRender</code></pre> 中,您有一个 DrawingContext,可以使用 DependenyProperties 绘制所需的形状。</p> <p>在这些之后,您可以像这样在 xaml 中使用装饰器:</p> <pre><code>&lt;localdecorators:ArrowBorderDecorator ArrowBaseHalfSegment=&#34;0&#34; FillColor=&#34;{DynamicResource MahApps.Brushes.Accent3}&#34; StrokeColor=&#34;{DynamicResource MahApps.Brushes.ThemeForeground}&#34; ArrowBorderThickness=&#34;1&#34; ArrowTipToArrowTriangleBaseDistance=&#34;10&#34;&gt; &lt;TextBlock Text=&#34;{Binding Path=Title}&#34; Foreground=&#34;{DynamicResource MahApps.Brushes.IdealForeground}&#34; Padding=&#34;10 1 10 1&#34; VerticalAlignment=&#34;Center&#34; FontWeight=&#34;Bold&#34;&gt; &lt;/TextBlock&gt;&lt;/localdecorators:ArrowBorderDecorator&gt; </code></pre> <p><a href="https://i.stack.imgur.com/bETwO.png" target="_blank"><img src="https://cdn.imgupio.com/i/AWkuc3RhY2suaW1ndXIuY29tL2JFVHdPLnBuZw==" alt=""/></a> <a href="https://i.stack.imgur.com/njfyp.png" target="_blank"><img src="https://cdn.imgupio.com/i/AWkuc3RhY2suaW1ndXIuY29tL25qZnlwLnBuZw==" alt=""/></a></p> </answer> </body></html>

回答 0 投票 0

如何在FakeHttpContext中设置Request.Header进行单元测试

我有一个 FakeHttpContext 我一直在尝试修改以包含一些用于测试目的的标头 公共静态 HttpContext FakeHttpContext() { var httpRequest = new HttpRequest("", "http://

回答 2 投票 0

任务未从另一个任务运行

在.Net 4.5中 此方法将任务添加到列表中。 //该方法返回日期时间。 var task = Task.Factory.StartNew(() => ProcessPost(_blockSize), token); 任务。添加(任务); 我还想再跑一次

回答 1 投票 0

将多个pdf下载到zip文件夹中

所以我试图一次将所有已付款发票下载为pdf。但是当我下载一张发票时,代码可以工作,但是对于多张发票,它返回错误500。 多张发票的代码 公开

回答 1 投票 0

WPF树视图,如何更改缩进

我的树视图基本上有“文件夹”节点,以及不包含其他项目的项目下面的一层。 因此,不需要用于展开/折叠图标的空间(在第 2 层)。我可以放弃吗...

回答 2 投票 0

ntdll.dll 中的应用程序崩溃,版本:6.1.7601.23677,.Net Framework 版本:v4.0.30319

我的应用程序在更新.Net框架后经常崩溃。以下是在事件查看器中找到的应用程序事件日志, 错误应用程序名称:MyApp.exe,版本:我的应用程序版本,...

回答 1 投票 0

.Net 4.5,如何通过.NET Framework配置更改区域安全设置

在 .net 1.1 中我们可以这样做: 转至 Windows 开始菜单中的“控制面板”。 选择“管理工具”(双击) 选择“Microsoft .NET Framework 配置” 单击“配置”

回答 1 投票 0

AuthorizationContext.Principal 会自动从 ClaimsPrincipal 更改为 GenericPrincipal

我不知道为什么 AuthorizationManager 中的上下文原则会发生变化。我的代码就像 公共类 AuthorizationManager :ClaimsAuthorizationManager { 公共覆盖 bool CheckAcc...

回答 2 投票 0

Windows Server 2016 IIS 10 应用程序池不断崩溃

我们正在尝试将当前托管在 Windows 2008 R2 服务器中的旧版 IIS 7 托管应用程序迁移到 Windows 2016 IIS 10 实例。该应用程序已构建并针对 4.5 .net

回答 0 投票 0

有没有办法将字节转换为 IFormFile c# .net 4.5

我有一个在.NET 4.5中实现的项目,由于某种原因,我无法更改它。我想将照片发布到使用 .NET Core 实现的 Web API。 API端点使用HTTP POST,它的i...

回答 0 投票 0

等待 FormClosing 事件中的异步函数

我遇到一个问题,我无法在 FormClosing 事件中等待异步函数,该函数将确定表单关闭是否应该继续。我创建了一个简单的例子

回答 6 投票 0

将 zip 文件的字节数组转换回 zip 文件

我正在使用以下代码下载存储在 GitLab 中的 zip 文件: 使用 (HttpClientHandler handler = new HttpClientHandler()) { ServicePointManager.Expect100Continue = true; ...

回答 2 投票 0

C# 处理 SQL 查询的最佳方式

我想用一个函数读取数据库记录并将结果作为数组传递给另一个函数。我如何使用 .NET4.5 做到这一点? 命名空间测试 { 课程计划 { 静态无效主要() ...

回答 4 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.