我遇到的问题是,如果我将文本框的宽度设置为70以下,它将无法完全显示。我将MinWidth
设置为0,而TextBox
仍显示为下图中的下部文本框。我将鞋帮的宽度设置为70,并完全显示。我需要在模板中进行一些更改才能使其正常工作吗?有什么想法吗?
<TextBox
Width="30"
Height="50"
MinWidth="0" />
我还尝试在Visual Studio设计器中编辑TextBox
的模板。我单击了编辑模板,但没有任何反应,但它与其他控件配合正常。
我的原始代码: 我将第一个文本框的宽度设置为50,其余部分设置为70。
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Margin="10,0">
<controls:DropShadowPanel
BlurRadius="40"
ShadowOpacity="0.3"
Color="{StaticResource blueColor}">
<TextBox
Width="50"
x:Name="Code0"
Height="80"
MinWidth="0"
Background="White"
BorderBrush="{StaticResource blueColor}"
BorderThickness="1"
CornerRadius="10"
FontSize="55"
TextAlignment="Center" />
</controls:DropShadowPanel>
</Grid>
<Grid Grid.Column="1" Margin="10,0">
<controls:DropShadowPanel
BlurRadius="40"
ShadowOpacity="0.3"
Color="{StaticResource blueColor}">
<TextBox
Width="70"
x:Name="Code1"
Height="80"
MinWidth="0"
Background="White"
BorderBrush="{StaticResource blueColor}"
BorderThickness="1"
CornerRadius="10"
FontSize="55"
TextAlignment="Center" />
</controls:DropShadowPanel>
</Grid>
...
更新:
<controls:DropShadowPanel
BlurRadius="40"
Width="80"
Background="Red"
ShadowOpacity="0.3"
Color="{StaticResource blueColor}">
<TextBox
x:Name="Code0"
Width="50"
Height="80"
MinWidth="0"
MaxWidth="65"
Background="White"
BorderBrush="{StaticResource darkText}"
BorderThickness="1"
CornerRadius="10"
HorizontalContentAlignment="Center"
FocusVisualPrimaryBrush="{StaticResource blueColor}"
FocusVisualSecondaryBrush="{StaticResource blueColor}"
FontSize="55"
KeyDown="TwoFactorKeyDown"
TextAlignment="Center" />
</controls:DropShadowPanel>
答案 0 :(得分:1)
Uwp不能将文本框的宽度减小到小于70
红色圆圈区域是“文本框边框”。并且它的MinHeight
和MinWidth
分别是TextControlThemeMinHeight
和TextControlThemeMinWidth
。因此,如果您仅拥有MinWidth
属性,则边框MinWidth
不会改变。 / p>
<Border x:Name="BorderElement"
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="{TemplateBinding CornerRadius}"
Grid.ColumnSpan="2" Grid.Column="0"
Control.IsTemplateFocusTarget="True"
MinHeight="{ThemeResource TextControlThemeMinHeight}"
MinWidth="{ThemeResource TextControlThemeMinWidth}"
Grid.RowSpan="1"
Grid.Row="1"/>
如果您想完全更改TextBox的最小宽度,则可以在“资源”页面中添加以下内容
<Page.Resources>
<x:Double x:Key="TextControlThemeMinHeight">32</x:Double>
<x:Double x:Key="TextControlThemeMinWidth">0</x:Double>
</Page.Resources>
答案 1 :(得分:0)
好的,所以我认为您的文本框不是问题。我相信您的问题在于控件的宽度:DropShadowPanel。我怀疑您的网格列正在调整为文本框的大小,但是您的DropShadowPanel只是被剪切或切断。尝试将DropShadowPanel的宽度设置为60(这将为文本框周围的边框和渐变留出一些额外的空间),这还将迫使列调整为DropShadowPanel的宽度。