2017-12-16 19 views
1

私はテキストボックスにいくつかのバリデーションを行う必要があります。 問題は、パネルが完全な不透明度を持っていても、未確認のテキストボックス上にパネルを置いたときに、赤い色の枠線がまだテキストボックスの上にあるパネルに表示されている場合です。 おそらくWPFのテキストボックスのバグです。テキストボックス上のパネルにテキストボックスの境界線の赤色が表示される

私はこの問題を生成するには、以下のコードを持っている: XAML:ファイルの

<Window x:Class="RedTextBoxFix.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:RedTextBoxFix" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="350" Width="525"> 
    <StackPanel Margin="5"> 
     <Canvas Panel.ZIndex="6000" Name="panel2" Margin="5"> 
      <Expander Background="LightGray" ExpandDirection="Right" 
         Header="Expand over the textbox.." 
         VerticalAlignment="Top" 
         HorizontalAlignment="Left"> 
       <StackPanel Width="900" Height="600"> 
       </StackPanel> 
      </Expander> 
     </Canvas> 
     <StackPanel Name="panel1" Visibility="Visible" Margin="5"> 
      <TextBox Name="DataBoundTextBox" Height="20" Width="100" HorizontalAlignment="Center" VerticalAlignment="Center"> 
       <Binding Path="TextValue"> 
        <Binding.ValidationRules> 
         <ExceptionValidationRule/> 
        </Binding.ValidationRules> 
       </Binding> 
      </TextBox> 
     </StackPanel> 
    </StackPanel> 
</Window> 

コード:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 

namespace RedTextBoxFix 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 

      this.DataContext = new MyClass("RemoveThisText"); 



     } 
     public class MyClass : INotifyPropertyChanged 
     { 

      private string mTextValue; 

      public MyClass(string defaultText) 
      { 
       TextValue = defaultText; 
      } 

      public string TextValue 
      { 
       get 
       { 
        return mTextValue; 
       } 
       set 
       { 
        mTextValue = value; 
        if (string.IsNullOrEmpty(mTextValue)) 
        { 
         throw new ApplicationException("Text value cannot be empty"); 
        } 
        OnPropertyChanged(new PropertyChangedEventArgs("TextValue")); 
       } 
      } 

      public event PropertyChangedEventHandler PropertyChanged; 

      protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) 
      { 
       if (this.PropertyChanged != null) 
       { 
        this.PropertyChanged(this, e); 
       } 
      } 
     } 
    } 
} 

製造工程:

WPFで(1)コピーペーストコードをプロジェクトとlauchアプリケーション。

(2)テキスト全体を押してタブを削除し、その後、テキストボックス

の赤い枠を持っている(3)エキスパンダーを展開します。

これで、エキスパンダーパネル上に予期しない赤い枠線が表示されました。どちらを削除する必要があります。 どのように?それは何の助けてもらえますか?

+0

[wpfエラーテンプレート - エキスパンダーの折りたたみ時に赤いボックスが表示される可能性があります。](https://stackoverflow.com/questions/1471451/wpf-error-template-red-box-still-visible-on-崩壊の - エキスパンダー) – Clint

答えて

1

AdornerはUIElementにバインドされたカスタムFrameworkElementです。装飾子はAdornerLayerにレンダリングされます.AdornerLayerは、常に装飾された要素または装飾された要素のコレクションの上にある描画面です。

とりわけ、アドオンは、視覚的なフィードバックを提供するために使用されます。ウィンドウにはAdornerDecoratorがあり、すべての上にあり、AdornerLayerが含まれています。それはエラーを示すあなたのアドナーがレンダリングされる場所です。したがって、Canvasの下に1つ必要です。TextBoxの周りに1つだけ追加できます。

<StackPanel Name="panel1" Visibility="Visible" Margin="5"> 
    <AdornerDecorator> 
     <TextBox Name="DataBoundTextBox" Height="20" Width="100" HorizontalAlignment="Center" VerticalAlignment="Center"> 
      <Binding Path="TextValue"> 
       <Binding.ValidationRules> 
        <ExceptionValidationRule/> 
       </Binding.ValidationRules> 
      </Binding> 
     </TextBox> 
    </AdornerDecorator> 
</StackPanel> 

詳細については、Microsoft Docsをご覧ください。

+0

それは素晴らしい答えは@djomlastic :) –

関連する問題