WPF密码箱圆角
我用它来绕过文本框的各个角落WPF密码箱圆角,wpf,xaml,Wpf,Xaml,我用它来绕过文本框的各个角落 <ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}"> <Border Background="{TemplateBinding Background}" x:Name="Bd" BorderBrush="#FFE6DDDD" BorderThickness=
<ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}">
<Border Background="{TemplateBinding Background}"
x:Name="Bd" BorderBrush="#FFE6DDDD"
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10">
<ScrollViewer x:Name="PART_ContentHost"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
<Trigger Property="Width" Value="Auto">
<Setter Property="MinWidth" Value="100"/>
</Trigger>
<Trigger Property="Height" Value="Auto">
<Setter Property="MinHeight" Value="20"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
我申请
<TextBox Template="{StaticResource TextBoxBaseControlTemplate}"
Height="25"
Margin="168,100,139,194"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Background="{x:Null}"
BorderBrush="{x:Null}"
FontFamily="Aller Light">
</TextBox>
任务完成
然后我想在PasswordBox中
<ControlTemplate x:Key="passwordbox" TargetType="{x:Type PasswordBox}">
<Border Background="{TemplateBinding Background}"
x:Name="Bd" BorderBrush="#FFE6DDDD"
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10">
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
<Trigger Property="Width" Value="Auto">
<Setter Property="MinWidth" Value="100"/>
</Trigger>
<Trigger Property="Height" Value="Auto">
<Setter Property="MinHeight" Value="20"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
申请
似乎成功了,但内容无法输入。(第二框)
如果我删除模板,通常是
如何修复它?谢谢…您的
密码箱
控制模板遗漏了名为“part\u ContentHost”的部分(通常是ScrollViewer
)。以TextBoxBase
模板为例
因此,您的temaplate应该是:
<ControlTemplate x:Key="passwordbox" TargetType="{x:Type PasswordBox}">
<Border Background="{TemplateBinding Background}"
x:Name="Bd" BorderBrush="#FFE6DDDD"
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10">
<ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
<Trigger Property="Width" Value="Auto">
<Setter Property="MinWidth" Value="100"/>
</Trigger>
<Trigger Property="Height" Value="Auto">
<Setter Property="MinHeight" Value="20"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
我希望它能对您有所帮助。您的
密码箱
控制模板遗漏了一个名为“part\u ContentHost”(通常是滚动查看器
)的部分。以TextBoxBase
模板为例
因此,您的temaplate应该是:
<ControlTemplate x:Key="passwordbox" TargetType="{x:Type PasswordBox}">
<Border Background="{TemplateBinding Background}"
x:Name="Bd" BorderBrush="#FFE6DDDD"
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10">
<ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
<Trigger Property="Width" Value="Auto">
<Setter Property="MinWidth" Value="100"/>
</Trigger>
<Trigger Property="Height" Value="Auto">
<Setter Property="MinHeight" Value="20"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
我希望它能帮助您。看起来您忘记了
部分
。看起来您忘记了部分
。