Avalonia Grid 透過元件高度調整和強制空間重新配置 實現 隱藏列(Hide Row)/顯示列(Show Row) 範例

Avalonia Grid 透過元件高度調整和強制空間重新配置 實現 隱藏列(Hide Row)/顯示列(Show Row) 範例

Avalonia Grid 透過元件高度調整和強制空間重新配置 實現 隱藏列(Hide Row)/顯示列(Show Row) 範例


資料來源: copilot + 自己


XAML

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:VPOS_Avalonia.ViewModels"
        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.Views.MainWindow"
        x:DataType="vm:MainWindowViewModel"
        Icon="/Assets/sys.ico"
        Title="VPOS_Avalonia" Background="#ff194a6e" Loaded="Window_Loaded" Closed="Window_Closed">

    <Design.DataContext>
        <!-- This only sets the DataContext for the previewer in an IDE,
             to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
        <vm:MainWindowViewModel/>
    </Design.DataContext>

	<Grid x:Name="FullGrid" Margin="3">
		<Grid.RowDefinitions>
			<RowDefinition />
			<!--Workspace -->
			<RowDefinition Height="40" />
			<!--status column -->
		</Grid.RowDefinitions>

		<Grid x:Name="WorkspaceGrid" Margin="0,2,0,2" Grid.Row="0" Grid.Column="0">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="60"/>
				<!-- Menu -->
				<ColumnDefinition />
				<!-- Content -->
			</Grid.ColumnDefinitions>
			<Grid x:Name="MenuGrid" Margin="1,0,1,0" Grid.Row="0" Grid.Column="0">
				<Border x:Name="MenuBorder" BorderBrush="#194a6e" BorderThickness="1" CornerRadius="5">
					<StackPanel Spacing="5">
						<Border BorderThickness="2" BorderBrush="White">
							<Image x:Name="SettingsBtn" Source="/Assets/settings.png" PointerPressed="SettingsBtn_Clicked"/>
						</Border>
						<Border BorderThickness="2" BorderBrush="White">
							<Image x:Name="DevicesBtn" Source="/Assets/device.png" PointerPressed="DevicesBtn_Clicked"/>
						</Border>
						<Border BorderThickness="2" BorderBrush="White">
							<Image x:Name="SynchronizeBtn" Source="/Assets/synchronize.png" PointerPressed="SynchronizeBtn_Clicked"/>
						</Border>
						<Border BorderThickness="2" BorderBrush="White">
							<Image x:Name="LogoutBtn" Source="/Assets/logout.png" PointerPressed="LogoutBtn_Clicked"/>
						</Border>
					</StackPanel>
				</Border>
				<!--MenuBorder-->
			</Grid>
			<!--MenuGrid-->
			<Grid x:Name="ContentGrid"
				  Grid.Row="0" Grid.Column="1" Margin="1,0,0,0"
				  ColumnDefinitions="5.4*,6.6*">
				<Border x:Name="LeftContentBorder" Grid.Row="0" Grid.Column="0"
					BorderThickness="1" BorderBrush="White" CornerRadius="5">

					<Grid x:Name="LeftContentGrid" RowDefinitions="3.3*,5.7*,2*">

						<Border x:Name="LeftContentBorder00" Grid.Row="0" Grid.Column="0"
							     BorderThickness="1" BorderBrush="White" CornerRadius="5">
							<Grid x:Name="ShowInfoGrid" RowDefinitions="1.3*,1.2*,0.8*">
								<Grid x:Name="ShowInfoGrid00"
										Margin="2,0" Grid.Row="0" Grid.Column="0"
										RowDefinitions="0.4*,0.3*,0.3*"
										ColumnDefinitions="*,*,*,*,*,*" IsEnabled="True">
									<TextBlock x:Name="OrderStatusLable"
										   Grid.Row="0" Grid.ColumnSpan="6"
										   Text="訂購中"
										   TextWrapping="WrapWithOverflow"
										   Foreground="#ff7f50"
										   FontSize="26"
										   VerticalAlignment="Center"
										   HorizontalAlignment="Center"/>

									<TextBlock x:Name="QuantityTextLable"
                                           Grid.Row="1" Grid.Column="0"
                                           Text="商品數量:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           Padding="5,0,0,0"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="QuantityValueLable"
                                           Grid.Row="1" Grid.Column="1"
                                           Text="10000"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="22"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="DiscountTextLable"
                                           Grid.Row="1" Grid.Column="2"
                                           Text="優惠金額:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="DiscountValueLable"
                                           Grid.Row="1" Grid.Column="3"
                                           Text="10000"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="22"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="ServiceTextLable"
                                           Grid.Row="1" Grid.Column="4"
                                           Text="服務費:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="ServiceValueLable"
                                           Grid.Row="1" Grid.Column="5"
                                           Text="10000"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="22"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>

									<TextBlock x:Name="ReceivableTextLable"
                                           Grid.Row="2" Grid.Column="0"
                                           Text="應收總額:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           Padding="5,0,0,0"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="ReceivableValueLable"
                                           Grid.Row="2" Grid.Column="1"
                                           Text="30000"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="22"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="ChangeValueLable"
                                           Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="4"
                                           Text="10000"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="Red"
                                           FontSize="20"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
								</Grid>

								<Grid x:Name="ShowInfoGrid01" Margin="2,0"
			                            Grid.Row="1" Grid.Column="0"
			                            RowDefinitions="2,*,*,*"
			                            ColumnDefinitions="1.09*,1.99*,1.09*,1.5*,0.9*,0.6*">

									<Separator x:Name="ShowInfoLine00" Grid.Row="0" Grid.ColumnSpan="6" Background="White" Height="2"/>

									<TextBlock x:Name="OrderNoTextLable"
                                           Grid.Row="1" Grid.Column="0"
                                           Text="訂單編號:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           Padding="5,0,0,0"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="OrderNoValueLable"
                                           Grid.Row="1" Grid.Column="1"
                                           Text="20230927-0001"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Center"/>
									<TextBlock x:Name="PickupNoTextLable"
                                           Grid.Row="1" Grid.Column="2"
                                           Text="取餐號:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="PickupNoValueLable"
                                           Grid.Row="1" Grid.Column="3"
                                           Text="00000001"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="VisitorsTextLable"
                                           Grid.Row="1" Grid.Column="4"
                                           Text="來客數:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="VisitorsValueLable"
                                           Grid.Row="1" Grid.Column="5"
                                           Text="0001"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Center"/>

									<TextBlock x:Name="OrderTypeTextLable"
                                           Grid.Row="2" Grid.Column="0"
                                           Text="訂單類型:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           Padding="5,0,0,0"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="OrderTypeValueLable"
                                           Grid.Row="2" Grid.Column="1"
                                           Text="Uber Eats"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Center"/>
									<TextBlock x:Name="TableNoTextLable"
                                           Grid.Row="2" Grid.Column="2"
                                           Text="桌號:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="TableNoValueLable"
                                           Grid.Row="2" Grid.Column="3"
                                           Text="豪華廳A0001"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="ShopNoTextLable"
                                           Grid.Row="2" Grid.Column="4"
                                           Text="牌號:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="ShopNoValueLable"
                                           Grid.Row="2" Grid.Column="5"
                                           Text="100"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Center"/>

									<TextBlock x:Name="MemberNameTextLable"
	                                       Grid.Row="3" Grid.Column="0"
	                                       Text="會員名稱:"
	                                       TextWrapping="WrapWithOverflow"
	                                       Foreground="#ff7f50"
	                                       FontSize="18"
	                                       Padding="5,0,0,0"
	                                       VerticalAlignment="Center"
	                                       HorizontalAlignment="Left"/>
									<TextBlock x:Name="MemberNameValueLable"
                                           Grid.Row="3" Grid.Column="1"
                                           Text="合用系統有限公司"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Center"/>
									<TextBlock x:Name="MemberTelTextLable"
                                           Grid.Row="3" Grid.Column="2"
                                           Text="會員電話:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="MemberTelValueLable"
                                           Grid.Row="3" Grid.Column="3"
                                           Text="04-22216292"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Center"/>
								</Grid>
								<Grid x:Name="ShowInfoGrid02" Margin="2,0" Grid.Row="2" Grid.Column="0"
			                            RowDefinitions="2,*,*"
			                            ColumnDefinitions="1*,1.3*,0.6*,1.31*,1.19*,0.6*">

									<Separator x:Name="ShowInfoLine01" Grid.Row="0" Grid.ColumnSpan="6" Background="White" Height="2"/>

									<TextBlock x:Name="InvoiceNoTextLable"
	                                       Grid.Row="1" Grid.Column="0"
	                                       Text="發票號碼:"
	                                       TextWrapping="WrapWithOverflow"
	                                       Foreground="#ff7f50"
	                                       FontSize="18"
	                                       Padding="5,0,0,0"
	                                       VerticalAlignment="Center"
	                                       HorizontalAlignment="Left"/>
									<TextBlock x:Name="InvoiceNoValueLable"
                                           Grid.Row="1" Grid.Column="1"
                                           Text="AB14433816"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<Border
	                                    BorderBrush="White"
	                                    BorderThickness="1"
                                        HorizontalAlignment="Stretch"
										VerticalAlignment="Stretch"
	                                    Background="#2470a0"
										CornerRadius="5"
	                                    Margin="2,2,2,2"
	                                    Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" >
										<TextBlock x:Name="TaxIDBtn" Text="客戶&#x0a;統編" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontSize="16"/>
									</Border>

									<TextBlock x:Name="InvoiceCountTextLable"
                                           Grid.Row="1" Grid.Column="3"
                                           Text="發票剩餘張數:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="InvoiceCountValueLable"
                                           Grid.Row="1" Grid.Column="4"
                                           Text="100"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Center"/>

									<Border
	                                    BorderBrush="White"
	                                    BorderThickness="1"
                                        HorizontalAlignment="Stretch"
										VerticalAlignment="Stretch"
										Background="#2470a0"
										CornerRadius="5"
                                        Margin="2,2,2,2"
                                        Grid.Row="1" Grid.Column="5" Grid.RowSpan="2" >
										<TextBlock x:Name="CarrierBtn" Text="發票&#x0a;載具" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontSize="16" />
									</Border>

									<TextBlock x:Name="TaxIDTextLable"
                                           Grid.Row="2" Grid.Column="0"
                                           Text="客戶統編:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           Padding="5,0,0,0"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="TaxIDValueLable"
                                           Grid.Row="2" Grid.Column="1"
                                           Text="42897648"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="20"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>

									<TextBlock x:Name="CarrierTextLable"
                                           Grid.Row="2" Grid.Column="3"
                                           Text="發票載具:"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="#ff7f50"
                                           FontSize="18"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
									<TextBlock x:Name="CarrierValueLable"
                                           Grid.Row="2" Grid.Column="4"
                                           Text="/RZDFEP2"
                                           TextWrapping="WrapWithOverflow"
                                           Foreground="White"
                                           FontSize="16"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left"/>
								</Grid>
							</Grid><!--ShowInfoGrid-->
						</Border><!--LeftContentBorder00-->

						<Border x:Name="LeftContentBorder01" Grid.Row="1" Grid.Column="0"
							BorderBrush="#194a6e" BorderThickness="1"
                            HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
							Background="White" CornerRadius="5" Margin="2,2,2,2">
							
							<Grid x:Name="ShopcartGrid"
                                  ColumnDefinitions="5.2*,0.8*">
								<Grid x:Name="ShopcartMainGrid" Margin="0,2,0,2"
                                    Grid.Row="0" Grid.Column="0"
                                    RowDefinitions="*,30,30" ColumnDefinitions="*">
									<ScrollViewer Grid.Row="0" Grid.Column="0" VerticalScrollBarVisibility="Visible">
										<ListBox x:Name="ShopcartListView" ItemsSource="{Binding m_ShopcartItems}" SelectionMode="Single" Background="White" SelectionChanged="ShopcartListView_ItemSelected">
											<ListBox.ItemTemplate>
												<DataTemplate>
													<!-- ListView 資料結構標準: ListView.ItemTemplate -> DataTemplate -> ViewCell-->
													<Grid Background="{Binding BColor}" ColumnDefinitions="30,15,4.4*,0.7*,1*,1.2*,7" Margin="8,4,0,8">
														<Image Source="{Binding Image00}" Width="20" Height="20" Grid.Column="0" PointerPressed="ShopcartListViewImage00_Clicked" />
														<Image Source="{Binding Image01}" Width="10" Height="10" Grid.Column="1" PointerPressed="ShopcartListViewImage01_Clicked" />
														<TextBlock Text="{Binding Name}"  FontSize="{Binding Font_Size}" HorizontalAlignment="{Binding NameTextAlignment}" VerticalAlignment="Center" Foreground="{Binding Font_Color}" Grid.Column="2"/>
														<TextBlock Text="{Binding Amount}"  FontSize="{Binding Font_Size}" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="{Binding Font_Color}" Grid.Column="3"/>
														<TextBlock Text="{Binding Price}"  FontSize="{Binding Font_Size}" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="{Binding Font_Color}" Grid.Column="4"/>
														<TextBlock Text="{Binding Sum}"  FontSize="{Binding Font_Size}" HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="{Binding Font_Color}" Grid.Column="5"/>
														<TextBlock Text="" FontSize="20" Foreground="Transparent"/>
													</Grid>
												</DataTemplate>
											</ListBox.ItemTemplate>
										</ListBox>
									</ScrollViewer>							
									<Grid x:Name="PromotionGrid" Grid.Row="1" Grid.Column="0" RowDefinitions="*"  ColumnDefinitions="*" Margin="0,0,0,3"><!--購物車促銷資訊-->
										<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" Grid.Row="0" Grid.Column="0" >
										    <TextBox x:Name="txtPromotion" AcceptsReturn="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="WrapWithOverflow" FontSize="20" Foreground="MediumBlue" Background="#FFFFDF" IsReadOnly="True"/>
									    </ScrollViewer>
									</Grid>
									<Grid x:Name="RemarkGrid" Grid.Row="2" Grid.Column="0" RowDefinitions="*"  ColumnDefinitions="*" Margin="0,0,0,3"><!--購物車備註資訊-->
										<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" Grid.Row="0" Grid.Column="0" >
										    <TextBox x:Name="txtRemark" AcceptsReturn="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="WrapWithOverflow" FontSize="20" Foreground="MediumBlue" Background="#FFFFDF" IsReadOnly="True"/>
									    </ScrollViewer>
									</Grid>
								</Grid>
								<Border x:Name="ShopcartBtnBorder" Grid.Row="0" Grid.Column="1"
										BorderBrush="White" BorderThickness="1"
                                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
										Background="#194a6e" CornerRadius="5">
									<StackPanel Orientation="Vertical" Margin="3" Spacing="8" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
										<local:CustBtn x:Name="RemarkBtn"
											    BorderColor="White" MinHeight="45"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Center"/>

										<local:CustBtn x:Name="ModifiedBtn"
											    BorderColor="White" MinHeight="45"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Center"/>

										<local:CustBtn x:Name="PlusBtn"
											    BorderColor="White" MinHeight="45"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Center"/>

										<local:CustBtn x:Name="MinusBtn"
											    BorderColor="White" MinHeight="45"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Center"/>

										<local:CustBtn x:Name="DeleteBtn"
											    BorderColor="White" MinHeight="45"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Center"/>

										<local:CustBtn x:Name="TemporaryBtn"
											    BorderColor="White" MinHeight="45"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Center"/>								
									</StackPanel>
                                </Border>
							</Grid>	<!--ShopcartGrid-->
						</Border><!--LeftContentBorder01-->
						<Border x:Name="LeftContentBorder02" Grid.Row="2" Grid.Column="0"
								BorderBrush="#194a6e" BorderThickness="1"
                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
								Background="White" CornerRadius="5">
							<Grid x:Name="ShopcartBtnGrid" Margin="1,2" 
								  RowDefinitions="*,*" ColumnDefinitions="*,*,*,*,*">
								<local:CustBtn x:Name="ShopcartBtn00"
                                                Grid.Row="0" Grid.Column="0"
											    BorderColor="White" Background="#194a6e"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
								<local:CustBtn x:Name="ShopcartBtn01"
                                                Grid.Row="0" Grid.Column="1"
											    BorderColor="White" Background="#194a6e"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
								<local:CustBtn x:Name="ShopcartBtn02"
                                                Grid.Row="0" Grid.Column="2"
											    BorderColor="White" Background="#194a6e"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
								<local:CustBtn x:Name="ShopcartBtn03"
                                                Grid.Row="0" Grid.Column="3"
											    BorderColor="White" Background="#194a6e"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
								<local:CustBtn x:Name="ShopcartBtn04"
                                                Grid.Row="0" Grid.Column="4" Grid.RowSpan="2"
											    BorderColor="White" Background="#194a6e"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
								<local:CustBtn x:Name="ShopcartBtn05"
                                                Grid.Row="1" Grid.Column="0"
											    BorderColor="White" Background="#194a6e"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
								<local:CustBtn x:Name="ShopcartBtn06"
                                                Grid.Row="1" Grid.Column="1"
											    BorderColor="White" Background="#194a6e"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
								<local:CustBtn x:Name="ShopcartBtn07"
                                                Grid.Row="1" Grid.Column="2"
											    BorderColor="White" Background="#194a6e"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
								<local:CustBtn x:Name="ShopcartBtn08"
                                                Grid.Row="1" Grid.Column="3"
											    BorderColor="White" Background="#194a6e"
                                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>								
							</Grid>
                        </Border><!--LeftContentBorder02-->

					</Grid><!--LeftContentGrid-->
				</Border><!--LeftContentBorder-->
				<Grid x:Name="MealsGrid" Grid.Row="0" Grid.Column="1"  ColumnDefinitions="0.9*,5.9*">
					<Border x:Name="MiddleContentBorder" Grid.Row="0" Grid.Column="0"
						BorderThickness="1" BorderBrush="White" CornerRadius="5">
						<StackPanel x:Name="MiddleVerticalStackLayout" Orientation="Vertical" Spacing="5" Margin="5,10,5,10">
						</StackPanel>
					</Border><!--MiddleContentBorder-->

					<Border x:Name="RightContentBorder" Grid.Row="0" Grid.Column="1"
							BorderThickness="1" BorderBrush="White" CornerRadius="5">
						<Grid x:Name="RightContentGrid"  RowDefinitions="2*,6*,3*">
						    <Border x:Name="RightContentBorder00" Grid.Row="0" Grid.Column="0"
	                                Background="White" BorderThickness="1" BorderBrush="#194a6e" CornerRadius="5">
								<Grid x:Name="CategoryBtnGrid" ColumnDefinitions="5*,0.5*">
									<Border x:Name="CategoryBtnBorder01" Grid.Row="0" Grid.Column="1"
		                                Background="#194a6e" BorderThickness="1" BorderBrush="White" CornerRadius="5">
										<Grid RowDefinitions="*,0.85*,*" Margin="0,3,0,3">
											<local:CustBtn x:Name="CategoryUpBtn" Grid.Row="0" Grid.Column="0"
											               Text="▲" TextSize="18" TextColor="White" Background="#194a6e" BorderColor="White"
                                                           HorizontalAlignment="Center" VerticalAlignment="Top" />
											<TextBlock x:Name="CategoryTextLable" Grid.Row="1" Grid.Column="0"
                                                       Text="1/2" TextWrapping="WrapWithOverflow" Foreground="White"
                                                       FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center" />
											<local:CustBtn x:Name="CategoryDownBtn" Grid.Row="2" Grid.Column="0"
												           Text="▼" TextSize="18" TextColor="White" Background="#194a6e" BorderColor="White"
                                                           HorizontalAlignment="Center" VerticalAlignment="Bottom" />
										</Grid>
									</Border>
								</Grid>
                            </Border><!--RightContentBorder00-->

							<Border x:Name="RightContentBorder01" Grid.Row="1" Grid.Column="0"
		                            Background="White" BorderThickness="1" BorderBrush="#194a6e" CornerRadius="5">
								<Grid x:Name="ProductBtnGrid" ColumnDefinitions="5*,0.5*">
									<Border x:Name="ProductBtnBorder01" Grid.Row="0" Grid.Column="1"
                                            Background="#194a6e" BorderThickness="1" BorderBrush="White" CornerRadius="5">
										<Grid RowDefinitions="*,0.3*,*">
											<local:CustBtn x:Name="ProductUpBtn" Grid.Row="0" Grid.Column="0"
											               Text="▲" TextSize="18" TextColor="White" Background="#194a6e" BorderColor="White"
                                                           HorizontalAlignment="Center" VerticalAlignment="Top" />
											<TextBlock x:Name="ProductTextLable" Grid.Row="1" Grid.Column="0"
                                                       Text="1/2" TextWrapping="WrapWithOverflow" Foreground="White"
                                                       FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center" />
											<local:CustBtn x:Name="ProductDownBtn" Grid.Row="2" Grid.Column="0"
												           Text="▼" TextSize="18" TextColor="White" Background="#194a6e" BorderColor="White"
                                                           HorizontalAlignment="Center" VerticalAlignment="Bottom" />											
										</Grid>
									</Border>
								</Grid>
							</Border><!--RightContentBorder01-->

							<Border x:Name="RightContentBorder02" Grid.Row="2" Grid.Column="0"
		                            Background="White" BorderThickness="1" BorderBrush="#194a6e" CornerRadius="5">
								<Grid x:Name="CondimentBtnGrid" ColumnDefinitions="5*,0.5*">
									<Border x:Name="CondimentBtnBorder01" Grid.Row="0" Grid.Column="1"
                                            Background="#194a6e" BorderThickness="1" BorderBrush="White" CornerRadius="5">
										<Grid RowDefinitions="*,0.3*,*">
											<local:CustBtn x:Name="CondimentUpBtn" Grid.Row="0" Grid.Column="0"
											               Text="▲" TextSize="18" TextColor="White" Background="#194a6e" BorderColor="White"
                                                           HorizontalAlignment="Center" VerticalAlignment="Top" />
											<TextBlock x:Name="CondimentTextLable" Grid.Row="1" Grid.Column="0"
                                                       Text="1/2" TextWrapping="WrapWithOverflow" Foreground="White"
                                                       FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center" />
											<local:CustBtn x:Name="CondimentDownBtn" Grid.Row="2" Grid.Column="0"
												           Text="▼" TextSize="18" TextColor="White" Background="#194a6e" BorderColor="White"
                                                           HorizontalAlignment="Center" VerticalAlignment="Bottom" />
										</Grid>										
                                    </Border>
								</Grid>
							</Border><!--RightContentBorder02-->
						</Grid><!--RightContentGrid-->
					</Border><!--RightContentBorder-->
				</Grid><!--MealsGrid-->

				<Grid x:Name="DiDiMoneyInfoGrid" Grid.Row="0" Grid.Column="1" RowDefinitions="1.0*,0.6*,3.6*,4.4*" Background="#194a6e">
					<!-- RowSpacing="20" -->
					<Border x:Name="DiDiLogoBorder" Grid.Row="0" Grid.Column="0" Margin="10,4,10,4"
							Background="#194a6e" BorderThickness="1" BorderBrush="White" CornerRadius="5">
						<Image Source="avares://VPOS_Avalonia/Assets/didimoney.png" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
					</Border>

					<Grid x:Name="DiDiFunctionGrid" Margin="30,10,30,0" Grid.Row="1" Grid.Column="0" ColumnDefinitions="*,*,*">
						<local:CustBtn x:Name="DiDiScanBtn" Grid.Row="0" Grid.Column="0" TextColor="White" Background="#194a6e" BorderColor="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="15,0"/>
						<local:CustBtn x:Name="DiDiClearBtn" Grid.Row="0" Grid.Column="1" TextColor="White" Background="#194a6e" BorderColor="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="15,0"/>
						<local:CustBtn x:Name="DiDiCloseBtn" Grid.Row="0" Grid.Column="2" TextColor="White" Background="#194a6e" BorderColor="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="15,0"/>
					</Grid>

					<Border x:Name="DiDiBaseInfoBorder" Grid.Row="2" Grid.Column="0" Margin="10,30,10,-10"
							Background="#194a6e" BorderThickness="1" BorderBrush="White" CornerRadius="5">
						<Grid x:Name="DiDiBaseInfosGrid" Margin="15,10,15,5" RowDefinitions="*,*,*,*,*,*,*" ColumnDefinitions="*,2*,*,2*">
							<!--RowSpacing="12" ColumnSpacing="10"-->
							<TextBlock x:Name="DiDiBaselab00" Text="會員電話 :" FontSize="16" Foreground="White" HorizontalAlignment="Center" Background="#194a6e" Margin="0,12,0,0" Grid.Row="0" Grid.Column="0"/>
							<TextBlock x:Name="DiDiBasetxt00" Background="White" Foreground="Blue" FontSize="20" Text="" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="17,12,0,0"/>

							<TextBlock x:Name="DiDiBaselab01" Text="會員姓名 :" FontSize="16" Foreground="White" HorizontalAlignment="Center" Background="#194a6e" Margin="0,12,0,0" Grid.Row="0" Grid.Column="2"/>
							<TextBlock x:Name="DiDiBasetxt01" Background="White" Foreground="Blue" FontSize="20" Text="中文" Grid.Row="0" Grid.Column="3" VerticalAlignment="Center" Margin="17,12,0,0"/>

							<TextBlock x:Name="DiDiBaselab10" Text="會員生日 :" FontSize="16" Foreground="White" HorizontalAlignment="Center" Background="#194a6e" Margin="0,12,0,0" Grid.Row="1" Grid.Column="0"/>
							<TextBlock x:Name="DiDiBasetxt10" Background="White" Foreground="Blue" FontSize="20" Text="0" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Margin="17,12,0,0"/>

							<TextBlock x:Name="DiDiBaselab11" Text="性        別 :" FontSize="16" Foreground="White" HorizontalAlignment="Center" Background="#194a6e" Margin="0,12,0,0" Grid.Row="1" Grid.Column="2"/>
							<TextBlock x:Name="DiDiBasetxt11" Background="White" Foreground="Blue" FontSize="20" Text="0" Grid.Row="1" Grid.Column="3" VerticalAlignment="Center" Margin="17,12,0,0"/>

							<TextBlock x:Name="DiDiBaselab21" Text="發票載具 :" FontSize="16" Foreground="White" HorizontalAlignment="Center" Background="#194a6e" Margin="0,12,0,0" Grid.Row="2" Grid.Column="0"/>
							<TextBlock x:Name="DiDiBasetxt21" Background="White" Foreground="Blue" FontSize="20" Text="" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Margin="17,12,0,0"/>

							<TextBlock x:Name="DiDiBaselab30" Text="會員地址 :" FontSize="16" Foreground="White" HorizontalAlignment="Center" Background="#194a6e" Margin="0,12,0,0" Grid.Row="3" Grid.Column="0"/>
							<Grid x:Name="DiDiAddrGrid00" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,0,0" ColumnDefinitions="1.3*,0.2*,1.5*">
								<TextBlock x:Name="DiDiAddrtxt00" Background="White" Foreground="Blue" FontSize="20" Text="" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="17,12,0,0"/>
								<TextBlock x:Name="DiDiAddrtxt01" Background="White" Foreground="Blue" FontSize="20" Text="" Grid.Row="0" Grid.Column="2" VerticalAlignment="Center" Margin="17,12,0,0"/>
							</Grid>
							<local:CustBtn x:Name="DiDiBaseBtn23" TextColor="White" Background="#194a6e" BorderColor="White" Grid.Row="4" Grid.Column="0" Margin="0,12,0,12"/>
							<TextBlock x:Name="DiDiAddrtxt11" Background="White" Foreground="Blue" FontSize="20" Text="" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="3" VerticalAlignment="Center" Margin="17,12,0,0"/>

							<Grid x:Name="DiDiInfosGrid" Grid.Row="5" Grid.Column="0" Margin="40,10,40,0" Grid.RowSpan="2" Grid.ColumnSpan="4" ColumnDefinitions="*,*,*">
								<!--ColumnSpacing="60"-->
								<Border x:Name="DiDiInfosBorder00" Grid.Row="0" Grid.Column="0" Margin="0,0,60,0"
										Background="#194a6e" BorderThickness="1" BorderBrush="White" CornerRadius="5">
									<TextBlock x:Name="DiDiInfostxt00" Background="#194a6e" Foreground="White" FontSize="20" Text="100" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2,2,2,2"/>
								</Border>
								<TextBlock x:Name="DiDiInfoslab00" Text="我的點數" FontSize="20" VerticalAlignment="Top" HorizontalAlignment="Left" Foreground="White" Background="#194a6e" Margin="15,-14,0,0" Grid.Row="3" Grid.Column="0"/>
								
								<Border x:Name="DiDiInfosBorder01" Grid.Row="0" Grid.Column="1" Margin="0,0,60,0"
										Background="#194a6e" BorderThickness="1" BorderBrush="White" CornerRadius="5">
									<TextBlock x:Name="DiDiInfostxt01" Background="#194a6e" Foreground="White" FontSize="20" Text="100" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2,2,2,2"/>
								</Border>
								<TextBlock x:Name="DiDiInfoslab01" Text="寄庫數量" FontSize="20" VerticalAlignment="Top" HorizontalAlignment="Left" Foreground="White" Background="#194a6e" Margin="15,-14,0,0" Grid.Row="3" Grid.Column="1"/>
								
								<Border x:Name="DiDiInfosBorder02" Grid.Row="0" Grid.Column="2" Margin="0,0,60,0"
										Background="#194a6e" BorderThickness="1" BorderBrush="White" CornerRadius="5">
									<TextBlock x:Name="DiDiInfostxt02" Background="#194a6e" Foreground="White" FontSize="20" Text="100" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2,2,2,2"/>
								</Border>
								<TextBlock x:Name="DiDiInfoslab02" Text="優惠券" FontSize="20" VerticalAlignment="Top" HorizontalAlignment="Left" Foreground="White" Background="#194a6e" Margin="15,-14,0,0" Grid.Row="3" Grid.Column="2"/>
							</Grid>
						</Grid>
					</Border>
					<TextBlock Text="會員資訊" FontSize="20" VerticalAlignment="Top" HorizontalAlignment="Left" Foreground="White" Background="#194a6e" Margin="25,15,0,0" Grid.Row="2" Grid.Column="0"/>

					<Border x:Name="DiDiAddrBorder00" Grid.Row="3" Grid.Column="0" Margin="10,40,10,10"
							Background="#194a6e" BorderThickness="1" BorderBrush="White" CornerRadius="5">
						<Grid x:Name="DiDiAddrGrid10" Margin="0,15,0,0" RowDefinitions="*,5*" ColumnDefinitions="0.2*,*,*,*,*,0.2*">
							<!--ColumnSpacing="25" RowSpacing="10"-->
							<local:CustBtn x:Name="DiDiCreateBtn" Margin="25,10" TextColor="White" Background="#194a6e" BorderColor="White" Grid.Row="0" Grid.Column="1" />
							<local:CustBtn x:Name="DiDiModifyBtn" Margin="25,10" TextColor="White" Background="#194a6e" BorderColor="White" Grid.Row="0" Grid.Column="2" />
							<local:CustBtn x:Name="DiDiDeleteBtn" Margin="25,10" TextColor="White" Background="#194a6e" BorderColor="White" Grid.Row="0" Grid.Column="3" />
							<local:CustBtn x:Name="DiDiLoaderBtn" Margin="25,10" TextColor="White" Background="#194a6e" BorderColor="White" Grid.Row="0" Grid.Column="4" />
							<ListBox x:Name="DiDiListBox" ItemsSource="{Binding m_DiDiItems}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="6" Margin="10,0,10,10" SelectionMode="Single"
									  Background="White" SelectionChanged="DiDiListBox_ItemSelected">
								<ListBox.ItemTemplate>
									<DataTemplate>
										<!-- ListBox 資料結構標準: ListBox.ItemTemplate -> DataTemplate -> ViewCell-->
										<Grid Background="{Binding BColor}" ColumnDefinitions="100,*" Margin="8,8,8,8">
											<TextBlock Text="{Binding Remark}"  FontSize="{Binding Font_Size}" HorizontalAlignment="{Binding NameTextAlignment}" VerticalAlignment="Center" Foreground="{Binding Font_Color}" Grid.Column="0" Margin="0,0,0,0"/>
											<TextBlock Text="{Binding FullAddress}"  FontSize="{Binding Font_Size}" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="{Binding Font_Color}" Grid.Column="1" Margin="0,0,0,0"/>
										</Grid>
									</DataTemplate>
								</ListBox.ItemTemplate>
							</ListBox>							
							
						</Grid>
					</Border>
					<TextBlock Text="常用地址" FontSize="20" VerticalAlignment="Top" HorizontalAlignment="Left" Foreground="White" Background="#194a6e"  Margin="25,26,0,0" Grid.Row="3" Grid.Column="0"/>
				</Grid>				
			</Grid><!--ContentGrid-->

		</Grid><!--WorkspaceGrid-->
		<Border x:Name="StatusBorder" Grid.Row="1" Grid.Column="0"
				BorderThickness="1" BorderBrush="White" CornerRadius="5">
			<Grid x:Name="StatusGrid" RowDefinitions="*" ColumnDefinitions="0.9*,2*,0.7*,1.1*,0.5*,0.6*,0.5*,2*,0.5*,0.8*,0.9*,1*,1.4*,0.5*" Margin="15,0">
				<TextBlock x:Name="Status00TextLable" VerticalAlignment="Center" Text="系統時間" FontSize="18" Foreground="White" Grid.Row="0" Grid.Column="0"/>
				<TextBlock x:Name="Status00ValueLable" VerticalAlignment="Center" Text="2022-12-15 11:36:13" FontSize="18" Foreground="#50c3d1" Grid.Row="0" Grid.Column="1"/>
				<TextBlock x:Name="Status01TextLable" VerticalAlignment="Center" Text="營業日" FontSize="18" Foreground="White" Grid.Row="0" Grid.Column="2"/>
				<TextBlock x:Name="Status01ValueLable" VerticalAlignment="Center" Text="2022-12-15" FontSize="18" Foreground="#50c3d1" Grid.Row="0" Grid.Column="3"/>
				<TextBlock x:Name="Status02TextLable" VerticalAlignment="Center" Text="班別" FontSize="18" Foreground="White" Grid.Row="0" Grid.Column="4"/>
				<TextBlock x:Name="Status02ValueLable" VerticalAlignment="Center" Text="早班" FontSize="18" Foreground="#50c3d1" Grid.Row="0" Grid.Column="5"/>
				<TextBlock x:Name="Status03TextLable" VerticalAlignment="Center" Text="機碼" FontSize="18" Foreground="White" Grid.Row="0" Grid.Column="6"/>
				<TextBlock x:Name="Status03ValueLable" VerticalAlignment="Center" Text="VT-POS-2022-00002" FontSize="18" Foreground="#50c3d1" Grid.Row="0" Grid.Column="7"/>
				<TextBlock x:Name="Status04TextLable" VerticalAlignment="Center" Text="版本" FontSize="18" Foreground="White" Grid.Row="0" Grid.Column="8"/>
				<TextBlock x:Name="Status04ValueLable" VerticalAlignment="Center" Text="v1.6.4.0" FontSize="18" Foreground="#50c3d1" Grid.Row="0" Grid.Column="9"/>
				<TextBlock x:Name="Status05TextLable" VerticalAlignment="Center" Text="網路狀態" FontSize="18" Foreground="White" Grid.Row="0" Grid.Column="10"/>
				<TextBlock x:Name="Status05ValueLable" VerticalAlignment="Center" Text="ON LINE" FontSize="18" Foreground="#50c3d1" Grid.Row="0" Grid.Column="11"/>
				<TextBlock x:Name="Status06TextLable" VerticalAlignment="Center" Text="待上傳筆數" FontSize="18" Foreground="White" Grid.Row="0" Grid.Column="12"/>
				<TextBlock x:Name="Status06ValueLable" VerticalAlignment="Center" Text="0" FontSize="18" Foreground="#50c3d1" Grid.Row="0" Grid.Column="13"/>
			</Grid>			
		</Border>
	</Grid><!--FullGrid-->

</Window>


CODE

//---
//電子發票資訊區域隱藏(移除)/顯示(插入)
public static bool m_blnInvoiceState = false;//啟用發票參數旗標 && 有發票參數
private void ShowInfoGrid02Show()
{

	POS_INVAPI.InitInvParamsVar();//初始化電子發票參數資訊變數函數
	m_blnInvoiceState = (SqliteDataAccess.m_terminal_data[0].invoice_active_state == "Y") && (POS_INVAPI.m_InvParams != null) && (POS_INVAPI.m_InvParams.Platform_Code != null) && (POS_INVAPI.m_InvParams.Platform_Code.Length > 0);

	if (m_blnInvoiceState)
	{
		if (!ShowInfoGrid02.IsVisible)
		{
			ShowInfoGrid02.IsVisible = true;
			/*
			GridLength height = new GridLength(0.8, GridUnitType.Star);
			RowDefinition RowDefinitionBuf = new RowDefinition(height);
			ShowInfoGrid.RowDefinitions.Insert(2, RowDefinitionBuf);
			*/
			GridLength height02 = new GridLength(0.8, GridUnitType.Star);
			ShowInfoGrid.RowDefinitions[2].Height = height02;

			GridLength height01 = new GridLength(1.2, GridUnitType.Star);
			ShowInfoGrid.RowDefinitions[1].Height = height01;

			GridLength height00 = new GridLength(1.3, GridUnitType.Star);
			ShowInfoGrid.RowDefinitions[0].Height = height00;

			ShowInfoGrid.InvalidateMeasure();// 強制更新佈局
		}

	}
	else
	{
		if (ShowInfoGrid02.IsVisible)
		{
			ShowInfoGrid02.IsVisible = false;
			/*
			ShowInfoGrid.RowDefinitions.RemoveAt(2);
			*/
			GridLength height = new GridLength(0, GridUnitType.Pixel);
			ShowInfoGrid.RowDefinitions[2].Height = height;

			ShowInfoGrid.InvalidateMeasure();// 強制更新佈局
		}
		if (SqliteDataAccess.m_terminal_data[0].invoice_active_state == "Y")
		{
			LogFile.Write($"Invoice Params Error: {JsonClassConvert.inv_params2String(POS_INVAPI.m_InvParams)}");
		}
	}
}
//---電子發票資訊區域隱藏(移除)/顯示(插入)

One thought on “Avalonia Grid 透過元件高度調整和強制空間重新配置 實現 隱藏列(Hide Row)/顯示列(Show Row) 範例

  1. Avalonia Grid 透過元件高度調整和強制空間重新配置 實現 隱藏列(Hide Row)/顯示列(Show Row) 範例

    元件隱藏

發表迴響

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