我在Listbox ItemTemplate / data模板中实现了文本块。它数据绑定到"数据"从xml文件中读取。一切正常但是,文本在文本块中被修剪,并且在那里有一个空白区域。我知道原因,这是由于文本块的限制。现在我尝试使用Alex Yakhnin博客的WP7 Scrollable TextBlock,但我无法理解如何在我的项目中实现这一点?
C#CODE:
string XMLTagNameBody = "page";
private void ParseHeaderBody()
{
XDocument SunderGutkaXMLInstance = XDocument.Load(xmlFileToOpen);
var XMLBody = from query in SunderGutkaXMLInstance.Descendants(XMLTagNameBody)
select new BodyContentClass
{
Data = (string)query.Element("data"),
};
ListBoxDisplayContent.ItemsSource = XMLBody;
}
public class BodyContentClass
{
string book;
string data;
public string Book
{
get { return book; }
set { book = value; }
}
public string Data
{
get { return data; }
set { data = value; }
}
}
XAML代码:
<ListBox Margin="0,25,0,32"
x:Name="ListBoxDisplayContent"
FontSize="48"
HorizontalAlignment="Center">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="ListBoxDisplayContentStackPanel"
Margin="10"
HorizontalAlignment="Center">
<TextBlock x:Name="MainContentDisplayTextBlock"
TextWrapping="Wrap"
Text="{Binding Data}"
TextAlignment="Center"
HorizontalAlignment="Center" />
<Image x:Name="dividerImage"
Stretch="Fill"
Source="/Assets/MainContentDivider.png"
Opacity="1"></Image>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Alex Yakhnin的Blog / Scrollable TextBlock for WP7的链接:
答案 0 :(得分:0)
您可以创建自定义控件,但可以将其添加到项目中,如:
<StackPanel x:Name="ListBoxDisplayContentStackPanel" Margin="10"
HorizontalAlignment="Center">
<my:ScrollableTextBlock Text="{Binding Data}"
HorizontalAlignment="Left" Name="scrollableTextBlock1"
VerticalAlignment="Top" Height="618" Width="427" Margin="12,-11,0,0" />
<TextBlock x:Name="MainContentDisplayTextBlock"
TextWrapping="Wrap"
TextAlignment="Center"
HorizontalAlignment="Center" />
<Image x:Name="dividerImage"
Stretch="Fill"
Source="/Assets/MainContentDivider.png"
Opacity="1"></Image>
</StackPanel>
我的是控件的命名空间。