我给ListView.ItemsTemplate.DataTemplate里的Grid设置宽度,结果发现第一项不见了。不设置宽度,正常显示。
<DataTemplate x:Key="GridViewKnowledgeSystemDiagramDataTemplateForPhone"> <Grid Height="40" VerticalAlignment="Center" HorizontalAlignment="Stretch" Width="{Binding ElementName=ListViewKnowledgeSystemDiagram,Path=ItemsPanelRoot.ActualWidth,Mode=OneWay}"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="40"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Image Source="{Binding ImageSource}" Stretch="Uniform" MaxWidth="40" MaxHeight="40" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2"/> <TextBlock FontSize="12" Text="{Binding Title}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="WrapWholeWords" Grid.Column="1" Grid.Row="0"/> <TextBlock FontSize="8" Text="{Binding SubTitle}" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="WrapWholeWords" Grid.Column="1" Grid.Row="1"/> </Grid> </DataTemplate> <Style x:Key="ListViewKnowledgeSystemDiagramStyles" TargetType="ListView"> <Setter Property="Background" Value="#FFE5E5E5"/> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden"/> <Setter Property="HorizontalContentAlignment" Value="Left"/> <Setter Property="ItemContainerStyle"> <Setter.Value> <Style TargetType="ListViewItem"> <Setter Property="Background" Value="White"/> <Setter Property="Margin" Value="5,5,5,0"/> <Setter Property="Padding" Value="0"/> </Style> </Setter.Value> </Setter> <Setter Property="ItemTemplateSelector"> <Setter.Value> <templateSelector:KnowledgeSystemDiagramDataTemplateSelector DataTemplateSelectionWhenTrue="{StaticResource GridViewKnowledgeSystemDiagramDataTemplateForPhone}" DataTemplateSelectionWhenFalse="{StaticResource GridViewKnowledgeSystemDiagramDataTemplateForPC}"/> </Setter.Value> </Setter> </Style>
设置宽度之前
设置宽度之后
我也遇到一样的问题,我是在PC上的UWP第一行会消失,但是图片还在,用vs2015实时可视化树打开去看,没找到原因,看起来并不是visibility的问题,在可视化树上点击地二行的时候,第二行的也消失了。头疼,求大神。