【发布时间】:2023-03-28 04:31:01
【问题描述】:
我需要根据里面的内容来设置翻转视图的高度。它应该是最大的元素。 Flipview 包含两个文本块,其中的文本可以有不同的大小。 我尝试了以下
Mainpage.xaml 摘录
<Page.DataContext>
<local:Msg/>
</Page.DataContext>
<Grid Background="LightBlue">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">-->
<FlipView x:Name="flipView1" Grid.Row="0" ItemsSource="{Binding CustomSearchResults}" Padding="20"
BorderBrush="Black" Background="#DEDEDE" BorderThickness="1" VerticalAlignment="Stretch" >
<FlipView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding Text1}" FontFamily="Segoe UI" TextWrapping="WrapWholeWords"
TextTrimming="CharacterEllipsis" Margin="0,0,0,20" />
<TextBlock Grid.Row="1" Text="{Binding Text2}" FontFamily="Segoe UI" TextWrapping="WrapWholeWords"
TextTrimming="CharacterEllipsis"
/>
</Grid>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
<!--</ScrollViewer>-->
</Grid>
datacontext 类摘录
public class CustomSearchResult
{
public string Text1 { get; set; }
public string Text2 { get; set; }
}
public class Msg
{
public Msg()
{
CustomSearchResults = new List<CustomSearchResult>();
CustomSearchResults.Add(new CustomSearchResult
{
Text1 = "Hardware Trends in 2021 - Online Computer Tips....",
Text2 = @"Famous chipmaker AMD developed a few new products. According to the latest rumors, along with the third-generation EPYC server processors, a brand new product Ryzen 5000,
desktop CPU based on Zen 3 architecture will be only the first of its kind, released in 2021."
});
CustomSearchResults.Add(new CustomSearchResult
{
Text1 = "What are the latest trends in hardware technology? – AnswersToAll",
Text2 = @"What are the latest trends in hardware technology? Current trends in hardware and software include the increasing use of reduced instruction-set computing, migration to the UNIX operating system, the development of large software libraries,
microprocessor-based smart terminals that allow remote validation of data, speech synthesis and recognition, application …"
});
CustomSearchResults.Add(new CustomSearchResult
{
Text1 = "Kitchen cabinet hardware 2021-2022: latest trends and stylish …",
Text2 = @"One of the 2022 kitchen trends is the geometric forms. We suggest you incorporate this idea into your kitchen cabinet hardware. It will offer the decor
a point of interest and emphasize the sharp lines of the cabinets. Furthermore, this design will integrate perfectly in any style and enrich it with stability. Large Text
Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text
Large Text"
});
}
public List<CustomSearchResult> CustomSearchResults { get; set; }
}
翻转视图的高度应该缩小到最大的内容。 我尝试将scrollviewer 包裹在flipview 周围,但没有成功。 我应用了 arttribute verticalalignment=stretch 没有运气。 我听说在自定义布局时使用了诸如 measureoverride() 之类的度量和排列阶段,但我不确定需要为此挂钩哪个事件
【问题讨论】:
-
这是不可能的。你不能那样做。
-
你能告诉我你为什么要实现这个目标吗?你想让你的
FlipView看起来更整洁还是有其他顾虑? -
只是为了节省空间