因此,我正在开发一个Windows 8应用程序,并使用我的工具包:FixedHtmlBlock来显示html内容。我的代码在下面
<mytoolkit:FixedHtmlTextBlock Html="{Binding Content}" FontSize="24" Foreground="{StaticResource AppForegroundColor}" />
我想自定义h3标记的样式,我在这里找到了以下文档:https://mytoolkit.codeplex.com/wikipage?title=HtmlTextBlock
它说我们可以使用下面的代码来定制样式
((ParagraphGenerator)((HtmlTextBlock)html).Generators["h2"]).FontSize = 26; ((ParagraphGenerator)((HtmlTextBlock)html).Generators["h3"]).FontSize = 20; ((ParagraphGenerator)((HtmlTextBlock)html).Generators["h3"]).FontStyle = FontStyles.Italic;
但我不知道该怎么用这些,或者放在哪里。有人能告诉我怎么使用这些密码吗?
更新:,因此<mytoolkit:FixedHtmlTextBlock x:Name="pcd" Html="{Binding Content}" FontSize="24" Foreground="{StaticResource AppForegroundColor}" />存储在视图/DataTemplate/Post1Detail.xaml中。
<DataTemplate x:Name="Posts1DetailLayout">
<Grid Margin="10,5,5,5">
<ScrollViewer>
<StackPanel>
<mytoolkit:FixedHtmlTextBlock Html="{Binding Title}" FontSize="32" Foreground="{StaticResource AppForegroundColor}"/>
<mytoolkit:FixedHtmlTextBlock x:Name="pcd" Html="{Binding Content}" FontSize="24" Foreground="{StaticResource AppForegroundColor}" />
</StackPanel>
</ScrollViewer>
</Grid>
</DataTemplate>在视图/posts.xaml中访问资源字典的方式为
<Grid x:Name="LayoutRoot" Background="{StaticResource AppBackgroundColor}">
<phone:Pivot Name="Container" Grid.Row="0" Foreground="{StaticResource AppForegroundColor}" Background="{StaticResource AppBackground}" SelectionChanged="OnSelectionChanged" toolkit:TiltEffect.IsTiltEnabled="True"
TitleTemplate="{StaticResource AppPivotTitle}"
HeaderTemplate="{StaticResource AppPivotHeader}"
ItemTemplate="{StaticResource Posts1DetailLayout}"
ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
</phone:Pivot>
</Grid>请注意,资源字典数据模板“Post1DetailLayout”正在ItemTemplate="{StaticResource Post1DetailLayout"}中使用。
在PostsDetail.xaml构造函数中,我尝试执行以下操作
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Navigation;
using System.Windows.Threading;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Net.NetworkInformation;
using Microsoft.Phone.Controls;
using MyToolkit.Paging;
using AppStudio.Data;
using AppStudio.Services;
using MyToolkit.Controls;
using MyToolkit.Controls.HtmlTextBlockImplementation.Generators;
using System.Windows.Resources;
using System.IO;
namespace AppStudio
{
public partial class PostsDetail
{
private bool _isDeepLink = false;
public PostsDetail()
{
InitializeComponent();
pcd.Generators["h3"] = new ParagraphGenerator()
{
FontSize = 26,
};
}我得到一个错误“名称pcd不存在于当前的上下文”。现在,如何访问资源字典中的fixedhtmltextblock名称,并在PostDetail构造函数中使用它呢?
发布于 2014-06-19 15:58:10
<mytoolkit:FixedHtmlTextBlock x:Name="YourHtmlBlock" Html="{Binding Content}" FontSize="24" Foreground="{StaticResource AppForegroundColor}" />
YourHtmlBlock.Generators["p"] = new ParagraphGenerator()
{
//change properties here :)
};如果您想要更改更多,可以定制ParagraphGenerator。
https://stackoverflow.com/questions/24083607
复制相似问题