Avalonia TextBox 當滑鼠移動到 TextBox 上時 如何停用背景色改變

Avalonia TextBox 當滑鼠移動到 TextBox 上時 如何停用背景色改變

Avalonia TextBox 當滑鼠移動到 TextBox 上時 如何停用背景色改變


資料來源: chatgpt + 自己


Code

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
		xmlns:local="clr-namespace:VPOS_Avalonia"
        x:Class="VPOS_Avalonia.Login"
		xmlns:vm="using:VPOS_Avalonia.ViewModels"
		x:DataType="vm:LoginViewModel"
        Title="VPOS" Loaded="Login_Loaded">

	<!--
		ViewModels 使用步驟:
			▲[固定語法(寫在axaml)] xmlns:vm="using:VPOS_Avalonia.ViewModels"
			▲[對應語法(寫在axaml)] x:DataType="vm:LoginViewModel"
			▲[對應語法(寫在axaml)] <Design.DataContext>
			▲[對應語法(寫在cs)] DataContext = new LoginViewModel();//建構子函數中資源檔載入[InitializeComponent();]前必須指定ViewModel
	-->
	<Design.DataContext>
		<vm:LoginViewModel/>
	</Design.DataContext>

	<Window.Styles>
		<Style Selector="TextBox">
			<Style.Setters>
				<!-- 禁用背景色的变化 : Avalonia Textbox 當滑鼠移動到 Textbox 上時 如何停用被景色改變-->
				<Setter Property="Background" Value="White"/>
				<Setter Property="BorderBrush" Value="Black"/>
			</Style.Setters>
		</Style>
	</Window.Styles>
	
	<Grid x:Name="FullGrid" RowDefinitions ="45,6.4*,0.6*" ColumnDefinitions="*,*" Background="#194a6e" Margin="5,5,5,5">
		<local:BaseButton x:Name="Close" Grid.Row="0" Grid.Column="1"
		       TextSize="30" Text="X" TextColor="White" BackgroundColor="#194a6e" BorderColor="#194a6e"
			   Width="45" Height="45" HorizontalAlignment="Right" VerticalAlignment="Top" ExternalClicked="Close_Clicked"/>
		
		<Grid x:Name="LeftGrid" Grid.Row="1" Grid.Column="0" Margin="13,10,13,21">
			<Border BorderBrush="White" BorderThickness="1" CornerRadius="10" >
				<ListBox x:Name="lvUser" SelectionMode="Single" ItemsSource="{Binding Items}" Background="White" SelectionChanged="lvUser_ItemSelected">
					<ListBox.ItemTemplate>
						<DataTemplate>
							<StackPanel Orientation="Horizontal" Spacing="10" Margin="5">
								<Image Source="{Binding ImageSource,Mode=TwoWay}" Width="50" Height="50" Margin="5" PointerPressed="Image_PointerPressed"/>
								<TextBlock Text="{Binding user_account,Mode=TwoWay}" FontSize="35" VerticalAlignment="Center" Margin="5"/>
							</StackPanel>
						</DataTemplate>
					</ListBox.ItemTemplate>
				</ListBox>
			</Border>
		</Grid>
		<Grid x:Name="RightGrid" Grid.Row="1" Grid.Column="1"  RowDefinitions ="1*,4*" Margin="13,10,13,21">
			<Border Grid.Row="0" BorderBrush="White" BorderThickness="1" CornerRadius="10" Margin="0,0,0,15">
				<Grid RowDefinitions ="*,*">
					<TextBlock x:Name="labUserName" Grid.Row="0" Text="" FontSize="35" VerticalAlignment="Center" Foreground="White" Margin="20,5"/>
					<TextBox x:Name="txtPassword" Grid.Row="1" PasswordChar="●" FontSize="40" Background="LightBlue" VerticalContentAlignment="Center" Watermark="Enter password" Margin="20,5" TextChanged ="txtPassword_TextChanged"/>
				</Grid>
			</Border>
			<Border Grid.Row="1" BorderBrush="White" BorderThickness="1" CornerRadius="10" Margin="0,5,0,0">
				<Grid RowDefinitions ="*,*,*,*" ColumnDefinitions="*,*,*,*">
					<local:BaseButton x:Name="Num01" Grid.Row="0" Grid.Column="0" Margin="10,10,10,10"
						   TextSize="30" Text="1" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="NumberBtn_Clicked"/>
					<local:BaseButton x:Name="Num02" Grid.Row="0" Grid.Column="1" Margin="10,10,10,10"
						   TextSize="30" Text="2" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="NumberBtn_Clicked"/>
					<local:BaseButton x:Name="Num03" Grid.Row="0" Grid.Column="2" Margin="10,10,10,10"
						   TextSize="30" Text="3" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="NumberBtn_Clicked"/>
					<Grid Grid.Row="0" Grid.Column="3" Grid.RowSpan="3" RowDefinitions ="*,*">
						<local:BaseButton x:Name="BtnC" Grid.Row="0" Margin="10,10,10,10"
							   TextSize="30" Text="C" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
							   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="BtnClear_Clicked"/>
						<local:BaseButton x:Name="BtnDel" Grid.Row="1" Margin="10,10,10,10"
							   TextSize="30" Text="Del" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
							   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="BtnDelete_Clicked"/>						
					</Grid>
						
					<local:BaseButton x:Name="Num04" Grid.Row="1" Grid.Column="0" Margin="10,10,10,10"
						   TextSize="30" Text="4" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="NumberBtn_Clicked"/>
					<local:BaseButton x:Name="Num05" Grid.Row="1" Grid.Column="1" Margin="10,10,10,10"
						   TextSize="30" Text="5" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="NumberBtn_Clicked"/>
					<local:BaseButton x:Name="Num06" Grid.Row="1" Grid.Column="2" Margin="10,10,10,10"
						   TextSize="30" Text="6" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="NumberBtn_Clicked"/>

					<local:BaseButton x:Name="Num07" Grid.Row="2" Grid.Column="0" Margin="10,10,10,10"
						   TextSize="30" Text="7" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="NumberBtn_Clicked"/>
					<local:BaseButton x:Name="Num08" Grid.Row="2" Grid.Column="1" Margin="10,10,10,10"
						   TextSize="30" Text="8" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="NumberBtn_Clicked"/>
					<local:BaseButton x:Name="Num09" Grid.Row="2" Grid.Column="2" Margin="10,10,10,10"
						   TextSize="30" Text="9" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="NumberBtn_Clicked"/>
					<Grid  Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" ColumnDefinitions ="*,*">
						<local:BaseButton x:Name="Num00" Grid.Column="0" Margin="10,10,10,10"
							   TextSize="30" Text="0" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
							   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="NumberBtn_Clicked"/>
						<local:BaseButton x:Name="BtnLogin" Grid.Column="1" Margin="10,10,10,10"
							   TextSize="30" Text="登入" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
							   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExternalClicked="BtnEnter_Clicked"/>
					</Grid>
				</Grid>
			</Border>
		</Grid>
		<Grid x:Name="EndGrid" Grid.Row="2" Grid.Column="0" Margin="20,5,20,15" ColumnDefinitions ="*,*" >
			<local:ImageButton x:Name="ResetBtn" Grid.Row="0" Grid.Column="0"
								TextSize="30" Text="重新開機" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						        ImageSource="/Assets/reset.png"
							    Width="200" VerticalAlignment="Stretch" ExternalClicked="ResetBtn_Clicked"/>
			<local:ImageButton x:Name="ShutdownBtn" Grid.Row="0" Grid.Column="1"
								TextSize="30" Text="關        機" TextColor="White" BackgroundColor="#194a6e" BorderColor="White"
						        ImageSource="/Assets/shutdown.png"
							    Width="200" VerticalAlignment="Stretch" ExternalClicked="ShutdownBtn_Clicked"/>			
		</Grid>
	</Grid>
</Window>

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *