我已經開始使用 WinUI 3,Microsoft 的新 UI 技術。
我有一個TextBox我想設定為只讀的,即IsReadOnly="True"(備注:用戶仍然可以從中復制內容,這就是為什么我不想將其設定為禁用,即IsEnabled="False"。)
將其設定IsReadOnly="True"為時,我注意到它TextBox仍然保持默認的白色背景。我想改變這一點,以避免讓用戶點擊它,因為他們認為可以改變它的內容。
我決定為背景設定某種灰色:
<TextBox IsReadOnly="True" Background="SlateGray" Text="The content..."></TextBox>
這按預期作業,但有一個問題:一旦滑鼠懸停在TextBox背景上,背景就會變回 white。當滑鼠不再位于 上時TextBox,顏色變回指定的灰色背景色。
在 WPF 中,我會嘗試一些 DataTrigger 以保持格式,但 WinUI 中沒有 DataTriggers(還沒有?)。
我還嘗試在 上設定其他與顏色相關的屬性,TextBox以查看它們是否與上述行為有關,但設定這些并沒有改變任何內容:
FocusVisualPrimaryBrush, FocusVisualSecondaryBrush, SelectionHighlightColor, SelectionHighlightColorWhenNotFocused
當滑鼠懸停在只讀`TextBox`上時,我愿意就如何保持背景顏色提出各種建議,謝謝。
uj5u.com熱心網友回復:
您可以覆寫一些主題資源:
<TextBox IsReadOnly="True" Background="SlateGray" Text="The content...">
<TextBox.Resources>
<SolidColorBrush x:Key="TextControlBackgroundPointerOver" Color="SlateGray" />
<SolidColorBrush x:Key="TextControlBackgroundFocused" Color="SlateGray" />
</TextBox.Resources>
</TextBox>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/346586.html
下一篇:當在Swift5中點擊TableviewRow時,如何使用Xib(不是StoryBoards)在SideMenuController中設定UINavigationController以推送新的View
