我想让我的TextBlock
滚动,但我不能让它工作。也许问题出在StackPanel
?
所以这里是代码:
<Grid Margin="3">
<Grid.RowDefinitions>
<RowDefinition Height="152*" />
<RowDefinition Height="86*" />
<RowDefinition Height="67*" />
</Grid.RowDefinitions>
<ListBox x:Name="lstItems" Margin="3,6,3,0" ItemsSource="{Binding Source={StaticResource rssData}}"
SelectedIndex="0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="20" Margin="3" Source="{Binding XPath=enclosure/@url}" />
<TextBlock Margin="3" VerticalAlignment="Center" Text="{Binding XPath=title}" FontWeight="Bold" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Grid.Row="1" Orientation="Vertical" DataContext="{Binding ElementName=lstItems, Path=SelectedItem}" Grid.RowSpan="2">
<StackPanel.ScrollOwner>
<ScrollViewer />
</StackPanel.ScrollOwner>
<TextBlock Margin="3" FontSize="13" FontWeight="Bold" Text="{Binding XPath=title, Path=InnerText}" />
<TextBlock Margin="3" Opacity="0.72" Text="{Binding XPath=pubDate}" />
<ScrollViewer>
<TextBlock ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="3" FontStyle="Italic" Text="{Binding XPath=description, Path=InnerText}" TextWrapping="Wrap" TextAlignment="Justify" Height="216" Width="489" AllowDrop="False" Foreground="#FF0000E7" FontFamily="Lucida Sans Unicode" />
</ScrollViewer>
</StackPanel>
</Grid>
问题出在这部分:
<ScrollViewer>
<TextBlock ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="3" FontStyle="Italic" Text="{Binding XPath=description, Path=InnerText}" TextWrapping="Wrap" TextAlignment="Justify" Height="216" Width="489" AllowDrop="False" Foreground="#FF0000E7" FontFamily="Lucida Sans Unicode" />
</ScrollViewer>
这部分代码应该可以滚动。我可以看到垂直滚动条但无法滚动。我希望能够看到,StackPanel
因为我不允许任何更改并且想要只读。
谢谢
编辑:
<Window x:Class="RssDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="RSS Demo" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="576" Width="521">
<Window.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE2E2E2" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Window.Background>
<Window.Resources>
<XmlDataProvider x:Key="rssData" XPath="//item" Source="http://www.hak.hr/rss/stanje/hr.xml" />
</Window.Resources>
<Grid Margin="3">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ListBox x:Name="lstItems" Margin="3,6,3,0" ItemsSource="{Binding Source={StaticResource rssData}}"
SelectedIndex="0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="20" Margin="3" Source="{Binding XPath=enclosure/@url}" />
<TextBlock Margin="3" VerticalAlignment="Center" Text="{Binding XPath=title}" FontWeight="Bold" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Grid.Row="1" Orientation="Vertical" DataContext="{Binding ElementName=lstItems, Path=SelectedItem}">
<TextBlock Margin="3" FontSize="13" FontWeight="Bold" Text="{Binding XPath=title, Path=InnerText}" />
<TextBlock Margin="3" Opacity="0.72" Text="{Binding XPath=pubDate}" />
</StackPanel>
<ScrollViewer Grid.Row="2" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<TextBlock ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="3"
FontStyle="Italic" Text="{Binding XPath=description, Path=InnerText}" TextWrapping="Wrap" TextAlignment="Justify" Width="489" AllowDrop="False"
Foreground="#FF0000E7" FontFamily="Lucida Sans Unicode" />
</ScrollViewer>
</Grid>
</Window>
将此代码粘贴到您的项目中,因为这是我阅读信息的 rss 链接。只是看看你会得到什么