文本框在浮出控件、UWP 商店应用程序中变为只读

Textbox is becoming readonly in flyout, UWP store app

在弹出按钮中,我在其中使用了一个用户控件,其中包含文本框。当 运行 应用程序文本框显示为只读时,不知道为什么我会遇到这个问题。我没有设置只读。

<TextBox Margin="2" Height="32" 
                     MaxHeight="60"
                     TextWrapping="Wrap"
                     HorizontalAlignment="Stretch" 
                     TextAlignment="Left"
                     Text="ramesh"
                     Style="{x:Null}"/>

鉴于提供的细节很少,很难确定任何答案,但由于 TextBox 的大小,我曾经看到过类似的东西。 UWP 文本框在框尾有一个 "delete" 按钮(一个小十字),用于删除当前内容。当 TextBox 垂直调整大小时,删除按钮会缩放以占据整个 TextBox,从而使其看起来只读。

如果您遇到类似问题,请尝试在文本框上设置 AcceptsReturn="True"InputScope="Text"

找出问题是因为周年更新。

https://blogs.msdn.microsoft.com/wsdevsol/2016/09/14/combobox-from-an-appbarbutton-loses-mouse-input-on-1607/

我为上面 link 中给出的解决方案创建了附件 属性。下面是附件属性

public class CompatExtensions
{
    public static bool GetAllowFocusOnInteraction(DependencyObject obj)
    {
        return (bool)obj.GetValue(AllowFocusOnInteractionProperty);
    }
    public static void SetAllowFocusOnInteraction(DependencyObject obj, bool value)
    {
        obj.SetValue(AllowFocusOnInteractionProperty, value);
    }
    // Using a DependencyProperty as the backing store for AllowFocusOnInteraction.  
    // This enables animation, styling, binding, etc...
    public static readonly DependencyProperty AllowFocusOnInteractionProperty =
        DependencyProperty.RegisterAttached("AllowFocusOnInteraction", 
                                            typeof(bool),
                                            typeof(CompatExtensions),
                                            new PropertyMetadata(0, AllowFocusOnInteractionChanged));

    private static bool allowFocusOnInteractionAvailable = 
        Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent(
            "Windows.UI.Xaml.FrameworkElement", 
            "AllowFocusOnInteraction");
    private static void AllowFocusOnInteractionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (allowFocusOnInteractionAvailable)
        {
            var element = d as FrameworkElement;
            if (element != null)
            {
                element.AllowFocusOnInteraction = (bool)e.NewValue;
            }
        }
    }
}

并使用了一个示例:

<AppBarButton local:CompatExtensions.AllowFocusOnInteraction="True" Icon="Setting">
    <AppBarButton.Flyout>
        <Flyout>
            <StackPanel Orientation="Vertical" >
                <ComboBox>
                    <ComboBoxItem Content="Red" IsSelected="True" />
                    <ComboBoxItem Content="Green" />
                    <ComboBoxItem Content="Blue"/>
                </ComboBox>
            </StackPanel>
        </Flyout>
    </AppBarButton.Flyout>
</AppBarButton>