Windows Phone 中的溢出文本块

本文关键字:文本 溢出 Phone Windows | 更新日期: 2023-09-27 18:33:30

我有以下堆栈面板的 XAML 代码,它将图像放在左侧,文本块放在右侧

<StackPanel Height="Auto" HorizontalAlignment="Stretch" Margin="12,0" Name="stackPanel1" VerticalAlignment="Top" Width="Auto" Grid.Row="1" Orientation="Horizontal" Background="White">           
        <Image Height="240" Name="image1" Stretch="Fill" Width="240" HorizontalAlignment="Left" />
        <Grid Height="Auto" Name="grid1" Width="Auto">
            <TextBlock Height="Auto" HorizontalAlignment="Left" Margin="6,6,0,0" Name="textBlock1" Text="CVC for strict action on tax evasions, black money" VerticalAlignment="Top" Width="Auto" Foreground="Black" FontSize="24" TextWrapping="Wrap" />
        </Grid>
    </StackPanel>

这会在文本块中生成溢出的文本,该文本超出边界。我想要一个堆栈面板,以便在更改图像大小时,文本块会相应地调整大小,并且整个堆栈面板始终保持拉伸状态。

编辑:整个 xaml 的整个代码是:

<phone:PhoneApplicationPage 
    x:Class="PanelFullStretch30_9_19_02.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
    d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <!--Pivot Control-->
        <controls:Pivot Title="MY APPLICATION" Background="Gainsboro" Foreground="Black">
            <!--Pivot item one-->
            <controls:PivotItem Header="first">
                <ListBox x:Name="ExampleBox">
                </ListBox>
            </controls:PivotItem>
            <!--Pivot item two-->
            <controls:PivotItem Header="second">
                <!--Triple line list no text wrapping-->
                <ListBox x:Name="SecondListBox">
                    <!-- Pic on left stackpanel design-->
                    <StackPanel Height="Auto" HorizontalAlignment="Stretch" Margin="12,0" Name="stackPanel1" VerticalAlignment="Top" Width="Auto" Grid.Row="1" Orientation="Horizontal" Background="White">
                        <Image Height="240" Name="image1" Stretch="Fill" Width="240" HorizontalAlignment="Left" />
                        <Grid Height="Auto" Name="grid1" Width="Auto">
                            <TextBlock Height="Auto" HorizontalAlignment="Left" Margin="6,6,0,0" Name="textBlock1" Text="CVC for strict action on tax evasions, black money" VerticalAlignment="Top" Width="Auto" Foreground="Black" FontSize="24" TextWrapping="Wrap" />
                        </Grid>
                    </StackPanel>
                </ListBox>
            </controls:PivotItem>
        </controls:Pivot>
    </Grid>
    <!--Sample code showing usage of ApplicationBar-->
    <!--<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
                <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->
</phone:PhoneApplicationPage>

Windows Phone 中的溢出文本块

每当需要自适应布局时,请使用 Grid .例如,以下 XAML 将生成一个包含两列的网格:左列自动调整大小,而第二列填充剩余空间:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
</Grid>

将图像放在第一列中,将文本放在第二列中。这将确保您想要的布局。