Uwp 无法将文本框的宽度降低到小于 70

Uwp cannot lower the width of textbox to less than 70

我遇到的问题是,如果我将文本框的宽度设置为低于 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>

好的,我认为您的文本框不是问题所在。我相信您的问题出在 controls:DropShadowPanel 的宽度上。我怀疑您的网格列正在调整文本框的大小,但您的 DropShadowPanel 只是被剪裁或截断。尝试将 DropShadowPanel 的宽度设置为 60(这将为文本框周围的边框和渐变留出一点额外空间),它还会强制列调整为 DropShadowPanel 的宽度。

Uwp cannot lower the width of textbox to less than 70

红圈区域为TextBox Border。而且它的MinHeightMinWidthTextControlThemeMinHeightTextControlThemeMinWidth。所以如果你只是MinWidth属性,边框MinWidth就不会被改变。

<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>