UniformGrid的XAML项目模板混淆了边距和位置

svgewumm  于 2023-11-14  发布在  其他
关注(0)|答案(1)|浏览(116)

我试图使一个统一的网格与项目销售作为查尔兹,但他们加入后,利润率和立场变得混乱。
它应该看起来像这样x1c 0d1x
但看起来这个

下面是代码!项目模板:

<UserControl x:Class="ShopWave.MVVM.ItemListingTemplate"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:ShopWave.MVVM"
         mc:Ignorable="d" 
         d:DesignHeight="500" d:DesignWidth="400">
<Border Margin="10"
        Background="#29303d"
        CornerRadius="5">

    <Grid Margin="0">

        <Image Source="\Images\placeholderImage.jpg"
               Width="300"
               Height="200"
               VerticalAlignment="Top"
               Margin="0,10,0,0"
               x:Name="img"/>

        <TextBlock Text="Name"
                   Foreground="White"
                   Width="290"
                   Height="40"
                   FontSize="25"
                   VerticalAlignment="Top"
                   HorizontalAlignment="Center"
                   Margin="-8,170,0,0"
                   x:Name="name"/>

        <TextBlock Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labo."
                   TextWrapping="WrapWithOverflow"
                   Foreground="LightGray"
                   TextAlignment="Left"
                   Height="200"
                   Width="285"
                   FontSize="20"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Margin="-8,120,0,0"
                   x:Name="dscp"/>

        <TextBlock Text="$16.99"
                   Foreground="DarkGray"
                   Width="90"
                   Height="30"
                   FontSize="25"
                   TextAlignment="Center"
                   VerticalAlignment="Center"
                   HorizontalAlignment="Center"
                   Margin="0,400,0,0"
                   x:Name="price"/>

        <Button Background="Transparent"/>
    </Grid>
</Border>

字符串
和统一网格的代码:

<UserControl x:Class="ShopWave.MVVM.View.ServiceView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:ShopWave.MVVM.View"
         mc:Ignorable="d" 
         Loaded="ServiceView_Loaded"
         d:DesignHeight="450" d:DesignWidth="800">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="11*"/>
        <RowDefinition Height="139*"/>
    </Grid.RowDefinitions>

    <TextBlock Text="Services" 
               Foreground="White"
               VerticalAlignment="Center"
               HorizontalAlignment="Left"
               Margin="20,0,0,0"
               FontSize="18"
               Grid.Row="0"/>

    <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
        <UniformGrid x:Name="serviceStackPanel"
                    Margin="10"
                    VerticalAlignment="Top">

        </UniformGrid>
    </ScrollViewer>
</Grid>


任何想法为什么会发生这种情况?任何帮助是感激!

3hvapo4f

3hvapo4f1#

你可以用这个代码

<UserControl x:Class="ShopWave.MVVM.ItemListingTemplate"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:local="clr-namespace:ShopWave.MVVM"
     mc:Ignorable="d" 
     d:DesignHeight="500" d:DesignWidth="400">
      <Button Margin="10"
    Background="#29303d"
    CornerRadius="5">
    <Button.Content>
<DockPanel>

    <Image Source="\Images\placeholderImage.jpg"
           Width="300"
           Height="200"
           VerticalAlignment="Top"
           Margin="0,10,0,0"
           x:Name="img"
           DockPanel.Dock="Top"/>

    <TextBlock Text="Name"
               Foreground="White"
               Width="290"
               Height="40"
               FontSize="25"
               VerticalAlignment="Top"
               HorizontalAlignment="Center"
               Margin="-8,170,0,0"
               x:Name="name"
               DockPanel.Dock="Top"/>

    <TextBlock Text="$16.99"
               Foreground="DarkGray"
               Width="90"
               Height="30"
               FontSize="25"
               TextAlignment="Center"
               VerticalAlignment="Center"
               HorizontalAlignment="Center"
               Margin="0,400,0,0"
               x:Name="price"
               DockPanel.Dock="Bottom"/>

<TextBlock Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
               Sed do eiusmod tempor incididunt ut labo."
               TextWrapping="WrapWithOverflow"
               Foreground="LightGray"
               TextAlignment="Left"
               Height="200"
               Width="285"
               FontSize="20"
               HorizontalAlignment="Center"
               VerticalAlignment="Center"
               Margin="-8,120,0,0"
               x:Name="dscp"/>
    </DockPanel>
</Button.Content>
</Button>

字符串

相关问题