Jas*_*ahl 5 c# xaml listview datatemplate windows-phone-8.1
我有一个带有ListView的Windows Phone 8.1项目,其后面的c#代码填充了它的itemssource.它工作,但我最终在单行文本块之间有空格.我已经尝试在文本块上设置高度,它位于列表视图内部.我尝试设置一个ItemContainerStyle,将高度绑定到文本块的高度,但它不起作用.
如果我将TextBlock的文本设置为Actual Height绑定,我得到0,所以我一定做错了.我很确定它与ListViewItems的高度有关,但由于它们是从代码填充的,我无法弄清楚如何让它们做我想做的事情.我也尝试切换到列表的ItemsControl但它似乎没有滚动和工作.这是Listview的XAML:
<ListView x:Name="TheList" IsHoldingEnabled="True"
ItemsSource="{Binding items}"
Loaded="WhenListViewBaseLoaded"
ContinuumNavigationTransitionInfo.ExitElementContainer="True"
IsItemClickEnabled="True">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Height" Value="{Binding ElementName=txtBibleText, Path=ActualHeight}"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid x:Name="ItemTemplateGrid" Holding="ListViewItem_Holding" Background="Blue">
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Share"
Click="ShareFlyoutItem_Click" />
<MenuFlyoutItem Text="Add to Sharing"
Click="AddSharingFlyoutItem_Click" />
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<Grid x:Name="gridText">
<TextBlock x:Name="txtBibleText"
FontSize="{Binding TheFontSize}"
Grid.Column="1"
VerticalAlignment="Top"
HorizontalAlignment="Left"
TextWrapping="Wrap"
Margin="0,0,0,0" FontFamily="Global User Interface">
<Run Text="{Binding VerseNumber}"/>
<Run Text="{Binding BibleText}"/>
</TextBlock>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)
填充ListView的代码背后:
XDocument loadedData = XDocument.Load(TranlationFilePath);
var data = from query in loadedData.Descendants("testament").Descendants("book").Descendants("chapter").Descendants("verse")
where (string)query.Parent.Parent.Parent.Attribute("name") == GetTestament
where (string)query.Parent.Parent.Attribute("name") == GetBibleBook
where (string)query.Parent.Attribute("number") == GetChapter
select new BibleLoad
{
VerseNumber = (string)query.Attribute("number"),
BibleText = (string)query.Value.ToString(),
TheFontSize = FontSize
};
TheList.ItemsSource = data;
Run Code Online (Sandbox Code Playgroud)
感谢您的时间.这是我第一次发帖提问,希望我做得对.我已经搜索,搜索和实验了很长一段时间.
编辑XML并缩短记录后.
关闭文本包装.
重新打开时,高度设置为20,最小高度设置为31.
MinHeight到20包装:
你为什么要设置 minheight 或 height ?尝试给出字体大小,它会调整本身的高度,保持 textwrapping=wrap...另一件事为什么要设置 grid.colum=1?..您只有 1 列。
归档时间: |
|
查看次数: |
1326 次 |
最近记录: |