简体   繁体   English

WPF属性在Windows 8中无法正常工作

[英]WPF properties not working correctly in windows 8

I am having an issue with the BorderThickness or BorderBrush property in Windows 8. 我在Windows 8中遇到BorderThickness或BorderBrush属性的问题。

In win7, the code below correctly outlines editControl in a 5px thick read outline, however it does not work in windows 8. I am wondering if there is something deprecated or unsupported in windows 8 now? 在win7中,以下代码在5px厚的读取轮廓中正确地勾勒了editControl,但是在Windows 8中不起作用。我想知道Windows 8现在是否已弃用或不支持某些东西? I cannot find any notion of that on the microsoft documentation. 我在Microsoft文档中找不到任何相关的概念。

editControl.BorderThickness = new Thickness(5);
editControl.BorderBrush = Brushes.Red;

Anyone able to help? 有人能帮忙吗?

I found a workaround using using Adorners . 我发现了使用Adorners的解决方法。

  private class ErrorHighlightAdorner : Adorner
  {
      public ErrorHighlightAdorner(UIElement adornedElement)
          : base(adornedElement)
      {
      }

      protected override void OnRender(DrawingContext drawingContext)
      {
          Rect sourceRect = new Rect();
          FrameworkElement fe = AdornedElement as FrameworkElement;
          if (fe != null)
          {
              sourceRect = new Rect(fe.RenderSize);
          }
          else
          {
              sourceRect = new Rect(AdornedElement.DesiredSize);
          }

          Pen renderPen = new Pen(new SolidColorBrush(Colors.Red), 2.0);
          drawingContext.DrawRectangle(null, renderPen, sourceRect);
      }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM