【问题标题】:mytoolkit:FixedHtmlBlock changing styles, xamlmytoolkit:FixedHtmlBlock 改变样式,xaml
【发布时间】:2014-07-27 19:53:24
【问题描述】:

所以我正在开发一个 Windows Phone 8 应用程序,并且我正在使用 mytoolkit: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}" /> 在下面给出的资源字典中,存储在 Views/DataTemplates/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>

资源字典在 Views/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>

注意ItemTemplate="{StaticResource Post1DetailLayout"}中使用了资源字典数据模板'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 构造函数中使用它?

【问题讨论】:

    标签: c# xaml windows-phone-8 mytoolkit


    【解决方案1】:
    <mytoolkit:FixedHtmlTextBlock x:Name="YourHtmlBlock" Html="{Binding Content}" FontSize="24"  Foreground="{StaticResource AppForegroundColor}" />
    
    
    YourHtmlBlock.Generators["p"] = new ParagraphGenerator()
    {
    //change properties here :)
    };
    

    如果您想更改更多内容,可以自定义 ParagraphGenerator。

    【讨论】:

    • 我在哪里使用 YourHtmlBlock.Generators["p"] = new ParagraphGenerator() { //在此处更改属性 :) };在页面的 .xaml.cs 文件中?以及是否需要添加任何程序集引用?
    • 如果可以的话,你能给我详细的说明吗?
    • 在页面构造函数中初始化后放置。
    • 这是我得到的错误The type or namespace name 'ParagraphGenerator' could not be found
    • 我遇到了更多问题。我已经发布了对上述问题的更新,请查看。
    猜你喜欢
    • 1970-01-01
    • 2018-06-24
    • 1970-01-01
    • 2010-10-05
    • 1970-01-01
    • 2015-10-23
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多