美好的一天,我如何将用户控件居中以适应另一个布局中网格的死点。我在其中心创建了一个带有图像按钮的用户控件。当我尝试添加此 UserControl 并将其置于另一个布局的网格布局中时,它变得非常不对齐。我怎样才能做到这一点?..非常感谢
我的用户控件 XAML:
<UserControl x:Class="MyApp.ImageFullScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}" Height="639.848">
<Grid HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,-10" Grid.RowSpan="4">
<Grid.RowDefinitions>
<RowDefinition Height="680"/>
</Grid.RowDefinitions>
<Canvas x:Name="ViewFinderCanvas" Margin="-12,-12,-471,51">
<!--Camera viewfinder -->
<Canvas.Background>
<VideoBrush x:Name="cameraviewfinder"/>
</Canvas.Background>
<Button x:Name="add_button" Canvas.Left="168" Canvas.Top="282" HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="0.5" RenderTransformOrigin="0.576,-0.098">
<Grid>
<Image x:Name="AddButtonImage" Source="/Assets/Images/add_button.png"/>
</Grid>
</Button>
</Canvas>
</Grid>
</UserControl>
Main_Layout XAML:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="48*"/>
<RowDefinition Height="680*"/>
<RowDefinition Height="48*"/>
</Grid.RowDefinitions>
<TextBox Grid.Column="1" HorizontalAlignment="Left" Height="62" Grid.Row="2" TextWrapping="Wrap" Text="page" VerticalAlignment="Top" Width="70" Margin="386,0,-17,-14" FontSize="10" Grid.ColumnSpan="2"/>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Margin="12,0,12,0" Grid.RowSpan="3"/>
<Grid Grid.Column="1" HorizontalAlignment="Left" Height="673" Grid.Row="1" VerticalAlignment="Top" Width="400">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--User control here-->
<local:ImageFullScreen x:Name="ImageFull" Grid.Column="1" Grid.Row="1" Loaded="ImageFullScreen_Loaded" Width="400" HorizontalAlignment="Left" RenderTransformOrigin="0.424,0.481"/>
</Grid>
</Grid>