0
我想爲我的控件SuperTextB編寫一個模板,在控件的TextBox的整個區域設置一個矩形。當驗證失敗時,此矩形將用於顯示驗證錯誤消息,並且在剩餘時間內將被隱藏。我試圖做的事情如下,但它並沒有真正奏效。Generic.xaml爲矩形垂直堆疊在上面的文本框?
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SuperTB">
<Style TargetType="{x:Type local:SuperTextB}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:SuperTextB}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Canvas x:Name="painting" Background="Red"
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height}"
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Width}">
<TextBox Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=TwoWay, UpdateSourceTrigger=LostFocus }" x:Name="PART_input"
Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Canvas, AncestorLevel=1}, Path=Height}"
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Canvas, AncestorLevel=1}, Path=Width}"
Canvas.ZIndex="1"/>
<Rectangle x:Name="PART_error"
Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Canvas, AncestorLevel=1}, Path=Height}"
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Canvas, AncestorLevel=1}, Path=Width}"
Canvas.ZIndex="2"/>
</Canvas>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
您可以擴展「它沒有真正的工作嗎?」有什麼問題? – itowlson