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...
Volatile.Read / Volatile.Write 是否为“双”原子?
MSDN 指出 long、ulong、double 和decimal 以及用户定义的类型不保证是原子的 5.5 变量引用的原子性 Will Volatile.Write方法(Double%,D...
我正在尝试实现 $maxTimeMS,同时尝试从 C# MongoDB 获取过滤器的计数。我不知道该怎么做。 我的 C# 代码: var doc = MongoDB.Bson.Serialization.
线程/任务和异步处理新手... 我有一个尝试获取文件的进程,但是,如果该文件受密码保护,则对 GetDocument 的调用永远不会返回,并挂起服务....
我有一个 .NET 4.0 中的 WPF 解决方案,其中包括一个单元测试项目,该项目测试 ViewModel 中使用的不同命令。一切都工作正常,但后来我安装了.NET 4.5 和 VS2012....
在具有不同屏幕分辨率和/或比例的显示器之间移动窗口时 WPF 中的视频渲染问题
我有一个 winforms 应用程序(嗯,它是一个在 Outlook 中运行的 VSTO Outlook 插件),我在其中使用工具栏,并在该工具栏中通过使用
在不同任务中同时使用 ClientWebSocket SendAsync 和 ReceiveAsync 方法时出现意外行为 (.Net Framework)
我的自定义 WebSocket 客户端(使用 System.Net.WebSockets 库)运行得很好。在内部,库有 2 个独立的任务:第一个任务是将命令发送到 Web 套接字服务器,例如...
创建自定义语音气泡工具提示,根据每种情况调整/放置其箭头/指针
我有一个 WPF 语音气泡工具提示,运行良好。 <Setter Property="OverridesDefaultStyle" ...</desc> <question vote="0"> <p>我有一个 WPF 语音气泡工具提示,运行良好。</p> <pre><code><Style x:Key="{x:Type ToolTip}" TargetType="ToolTip"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="HorizontalOffset" Value="1" /> <Setter Property="VerticalOffset" Value="1" /> <Setter Property="Background" Value="White" /> <Setter Property="Foreground" Value="Black" /> <Setter Property="FontSize" Value="12" /> <Setter Property="FontFamily" Value="Segoe UI" /> <Setter Property="DataContext" Value="{Binding Path=PlacementTarget.DataContext, RelativeSource={x:Static RelativeSource.Self}}"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ToolTip"> <Canvas Width="225" Height="131"> <Path x:Name="Container" Canvas.Left="0" Canvas.Top="0" Margin="0" Data="M8,7.41 L15.415,0 L22.83,7.41 L224,7.41 L224,130 L0,130 L0,7.41 L8,7.41" Fill="{TemplateBinding Background}" Stroke="Gray"> <Path.Effect> <DropShadowEffect BlurRadius="10" Opacity="0.5" ShadowDepth="4" /> </Path.Effect> </Path> <TextBlock Canvas.Left="10" Canvas.Top="10" Width="100" Height="65" Text="{TemplateBinding Content}" TextWrapping="WrapWithOverflow" /> </Canvas> </ControlTemplate> </Setter.Value> </Setter> </Style> </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("VerticalMargin", 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("HorizontalMargin", 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("PointerPosition", 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("AlignmentPosition", 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("PointerHeight", 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("PointerWidth", 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><localdecorators:BubbleTextDecorator PointerHeight="10" PointerWidth="20" PointerPosition="LeftSide" AlignmentPosition="Center" VerticalMargin="30" HorizontalMargin="30" HorizontalAlignment="Left"> <TextBlock Text="this" HorizontalAlignment="Center" VerticalAlignment="Center"/> </localdecorators:BubbleTextDecorator> </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("ArrowTipToArrowTriangleBaseDistance", 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><localdecorators:ArrowBorderDecorator ArrowBaseHalfSegment="0" FillColor="{DynamicResource MahApps.Brushes.Accent3}" StrokeColor="{DynamicResource MahApps.Brushes.ThemeForeground}" ArrowBorderThickness="1" ArrowTipToArrowTriangleBaseDistance="10"> <TextBlock Text="{Binding Path=Title}" Foreground="{DynamicResource MahApps.Brushes.IdealForeground}" Padding="10 1 10 1" VerticalAlignment="Center" FontWeight="Bold"> </TextBlock></localdecorators:ArrowBorderDecorator> </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>
如何在FakeHttpContext中设置Request.Header进行单元测试
我有一个 FakeHttpContext 我一直在尝试修改以包含一些用于测试目的的标头 公共静态 HttpContext FakeHttpContext() { var httpRequest = new HttpRequest("", "http://
在.Net 4.5中 此方法将任务添加到列表中。 //该方法返回日期时间。 var task = Task.Factory.StartNew(() => ProcessPost(_blockSize), token); 任务。添加(任务); 我还想再跑一次
所以我试图一次将所有已付款发票下载为pdf。但是当我下载一张发票时,代码可以工作,但是对于多张发票,它返回错误500。 多张发票的代码 公开
我的树视图基本上有“文件夹”节点,以及不包含其他项目的项目下面的一层。 因此,不需要用于展开/折叠图标的空间(在第 2 层)。我可以放弃吗...
ntdll.dll 中的应用程序崩溃,版本:6.1.7601.23677,.Net Framework 版本:v4.0.30319
我的应用程序在更新.Net框架后经常崩溃。以下是在事件查看器中找到的应用程序事件日志, 错误应用程序名称:MyApp.exe,版本:我的应用程序版本,...
.Net 4.5,如何通过.NET Framework配置更改区域安全设置
在 .net 1.1 中我们可以这样做: 转至 Windows 开始菜单中的“控制面板”。 选择“管理工具”(双击) 选择“Microsoft .NET Framework 配置” 单击“配置”
AuthorizationContext.Principal 会自动从 ClaimsPrincipal 更改为 GenericPrincipal
我不知道为什么 AuthorizationManager 中的上下文原则会发生变化。我的代码就像 公共类 AuthorizationManager :ClaimsAuthorizationManager { 公共覆盖 bool CheckAcc...
Windows Server 2016 IIS 10 应用程序池不断崩溃
我们正在尝试将当前托管在 Windows 2008 R2 服务器中的旧版 IIS 7 托管应用程序迁移到 Windows 2016 IIS 10 实例。该应用程序已构建并针对 4.5 .net
有没有办法将字节转换为 IFormFile c# .net 4.5
我有一个在.NET 4.5中实现的项目,由于某种原因,我无法更改它。我想将照片发布到使用 .NET Core 实现的 Web API。 API端点使用HTTP POST,它的i...
我遇到一个问题,我无法在 FormClosing 事件中等待异步函数,该函数将确定表单关闭是否应该继续。我创建了一个简单的例子
我正在使用以下代码下载存储在 GitLab 中的 zip 文件: 使用 (HttpClientHandler handler = new HttpClientHandler()) { ServicePointManager.Expect100Continue = true; ...
我想用一个函数读取数据库记录并将结果作为数组传递给另一个函数。我如何使用 .NET4.5 做到这一点? 命名空间测试 { 课程计划 { 静态无效主要() ...