首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mytoolkit:FixedHtmlBlock更改样式,xaml

mytoolkit:FixedHtmlBlock更改样式,xaml
EN

Stack Overflow用户
提问于 2014-06-06 13:57:16
回答 1查看 270关注 0票数 1

因此,我正在开发一个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中。

代码语言:javascript
复制
<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中访问资源字典的方式为

代码语言:javascript
复制
<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构造函数中,我尝试执行以下操作

代码语言:javascript
复制
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构造函数中使用它呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-19 15:58:10

代码语言:javascript
复制
<mytoolkit:FixedHtmlTextBlock x:Name="YourHtmlBlock" Html="{Binding Content}" FontSize="24"  Foreground="{StaticResource AppForegroundColor}" />


YourHtmlBlock.Generators["p"] = new ParagraphGenerator()
{
//change properties here :)
};

如果您想要更改更多,可以定制ParagraphGenerator。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24083607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档