簡體   English   中英

WPF按鈕內的內容將重點放在制表符上

[英]Content inside WPF button getting focus on tabbing

當我們通過鍵盤標簽操作應用程序時,按鈕“下一步”內的內容也將獲得標簽。

    <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="1"
                HorizontalAlignment="Right" VerticalAlignment="Bottom">
        <Button Name="HideWelcomePageButton"
                Visibility="{Binding Path=HideWelcomePageButton.IsVisible, Converter={StaticResource BoolToVisibilityConverter}}"
                IsEnabled="{Binding Path=HideWelcomePageButton.IsEnabled}" MinWidth="100"
                Command="{Binding Path=HideWelcomePageButton.ButtonCommand}" Margin="30 0 0 0"
                Content="Next">
        </Button>
    </StackPanel>

在此處輸入圖片說明

是否有任何設置可以禁用按鈕內部內容的焦點和制表位。 它應該只在按鈕上。

若要使按鈕可聚焦,但不能使其中的文本聚焦,則不能設置默認的Content屬性值,也不能在Button XAML標記內設置Label / TextBlock,然后將其聲明為不可聚焦。

<Button Name="HideWelcomePageButton"
            Visibility="{Binding Path=HideWelcomePageButton.IsVisible, 
            Converter={StaticResource BoolToVisibilityConverter}}"
            IsEnabled="{Binding Path=HideWelcomePageButton.IsEnabled}" 
            MinWidth="100"
            Command="{Binding Path=HideWelcomePageButton.ButtonCommand}" 
            Margin="30 0 0 0">
<Label Focusable="false">Next</Label>
</Button>

另一方面,如果您只想禁用按鈕的文本焦點的邊框,請添加屬性:

FocusVisualStyle="{x:Null}"放到按鈕控件上。

要重新啟用它,請將該屬性設置為您選擇的樣式。

資源

我通過添加屬性KeyboardNavigation.TabNavigation =“ None”來解決此問題,如下所示

<Button KeyboardNavigation.TabNavigation ="None" Content="{Binding NoButtonText}">

通過進行此更改,只有按鈕將焦點放在制表符上,而不是按鈕內的文本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM