Wpf文本框错误红色边框不正确显示文本框的宽度 [英] Wpf textbox error red border is not proper showing to the width of textbox

查看:634
本文介绍了Wpf文本框错误红色边框不正确显示文本框的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临一个问题,即一旦我的wpf页面被加载,然后需要的文本框显示红色边框不正确显示在文本框上。红色边框仅显示90%的文本框宽度未满。输入值后&从文本框中删除值,正确显示红色边框消息意味着显示红色边框100%宽度的文本框。



当我修复文本框的宽度时,红色边框是正确显示,但我想要文本框的响应宽度。





以下代码为:



Hi, I'm facing one problem that is once my wpf page is loaded then required textbox showing red border not proper displaying over textbox. The Red border displaying only 90% width of textbox not full. After enter the value & remove the value from textbox, Red border message is showing in properly means displaying Red border 100% width of textbox.

When I Fixed the width of textbox then red border is displaying properly but I want responsive width of textbox.


Following code is:

<TextBox x:Name="txt1" Text="{Binding CurrentItem.FirstName, Mode=TwoWay, ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}" Height="27" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="10 0 0 0" MaxLength="600"  />










<Style TargetType="TextBox">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="True">
                    <Setter Property="ToolTip"
                        Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                        Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
            </Style.Triggers>
        </Style>





我尝试过:



我试图修复texbox宽度,但我想要文本框宽度响应,这就是为什么无法修复。



What I have tried:

I tried to fix the texbox width but i want textbox width responsive that's why can not be fixed.

推荐答案





将文本框的宽度设置为auto,将Horizo​​ntalAlignment设置为Stretch。



祝你好运
Hey

Set the textbox's width to auto and HorizontalAlignment to Stretch.

Good Luck


这篇关于Wpf文本框错误红色边框不正确显示文本框的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆