locked
Embedded fonts in styles at runtime RRS feed

  • Question

  • This is kind of a re-post, and I apologize for that, but in doing a repro, I realized I hadn't described the problem accurately, and I only got one (well-meant, but irrelevant) response to my original. And not finding a solution to this will be a very.bad.thing...

    So, the problem is that when I have two stylesheets, one that defines the styles, and second that sets them as implicit, the embedded font is displayed correctly in the designer, but not at runtime.

    Steps to Repro:

    1. Add an embedded font to your project (I used BuxtonSketch)
    2. Create a basic ResourceDictionary file (mine is called PoCDefaults.xaml) that declares the font as a resource and contains a style that references the resource:

      <SolidColorBrush x:Key="BaseForeground-Sketch" Color="#FF606060"/>
      <FontFamily x:Key="FontFamily-Sketch">Fonts/#Buxton Sketch</FontFamily>

      <!-- Basic Sketch TextBlock -->
      <Style x:Key="TextBlock-PoC" TargetType="{x:Type TextBlock}">
      <Setter Property="FontFamily" Value="{DynamicResource FontFamily-Sketch}"/>
      <Setter Property="FontSize" Value="16"/>
      <Setter Property="Foreground" Value="{DynamicResource BaseForeground-Sketch}"/> </Style>
    3. Add a second ResourceDictionary that sets the TextBlock-PoC as the default for TextBlock controls:

      <Style TargetType="{x:Type TextBlock}" BasedOn="{Static Resource TextBlock-PoC}" />
    4. Reference both files in a MergedDictionary in App.xaml.
    5. Add a TextBlock to MainWindow. It displays correctly in the designer:

    But not at runtime:



    Rebecca M. Riordan

    Saturday, February 9, 2013 1:07 PM

Answers

All replies

  • Hi Rebecca M. Riordan,

    I tried your steps but cannot reproduce the same issue. The Font works fine in both design mode and runtime. Could you please share a minumum sample with us for further investigation?

    Best regards,


    Min Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 11, 2013 7:33 AM
  • Thanks for looking at it. Since you couldn't repro, which makes one suspect something quirky with my system, I repaired VS and re-created the repro app from scratch. All to no avail, I"m afraid; same result.

    I've posted the repro here:

    https://skydrive.live.com/redir?resid=B1F403554891440C!142


    Rebecca M. Riordan

    Tuesday, February 12, 2013 1:50 PM
  • Hi Rebecca M. Riordan,

    I changed two thing in your solution and it works good now.

    1. Edit the FontRepro.csproj file and remove the IsSystemFont tag under BlendEmbeddedFont.

        <BlendEmbeddedFont Include="Fonts\BuxtonSketch.ttf">
          <!--IsSystemFont>True</IsSystemFont-->
          <All>True</All>
          <AutoFill>True</AutoFill>
          <Uppercase>True</Uppercase>
          <Lowercase>True</Lowercase>
          <Numbers>True</Numbers>
          <Punctuation>True</Punctuation>
        </BlendEmbeddedFont>

    2. Move the two style from Style sub folder to the project folder.

    After that, clean the solution then everyhing will work good.

    I suggest you workaround the issue in this way for now.

    You can open a ticket on the Connect site to elaborate its impact to your business if you look forward to a future fix.

    Thanks again for your valuable feedback!

    Best regards,


    Min Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 13, 2013 2:38 AM
  • Min Zhu,

    Thanks, for working on it, but nope, your fix didn't work for me.

    I've opened a ticket on Connect, but I have to say, well, wow....embed a font in Blend and it breaks in Visual Studio. Kinda breaks that whole designer/developer workflow thing, doesn't it?


    Rebecca M. Riordan

    Wednesday, February 13, 2013 1:32 PM
  • Hi Rebecca M. Riordan,

    Have you place the ResoruceDictionary files into the project folder? I find it doesn't work if the resource are in any subfolder.

    Also, could you please post the link to your connect post so it might help others in futher?

    Thank you!


    Min Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 14, 2013 2:00 AM
  • Oops, sorry. Didn't think. The connect link is https://connect.microsoft.com/VisualStudio/feedback/details/779094/embedded-fonts-created-in-blend-do-not-display-at-runtime-in-visual-studio

    And yes, I have the resource dictionaries in the project and updated the csproj file. I've posted the revised version here: http://sdrv.ms/XN41VH

    I keep fiddling with it because I just can't believe that something this fundamental doesn't work. I keep looking for something stupid I've done, but I can't figure out what it is...


    Rebecca M. Riordan

    Thursday, February 14, 2013 2:22 AM
  • Thanks for the update.

    Strange. I change the BlendEmbeddedFont to Resource and it works. Maybe I also did it last time but didn't notice.

    <Resource Include="Fonts\BuxtonSketch.ttf"/>

    Honestly, I am not very familiar with Blend, you can try posting a question at http://social.msdn.microsoft.com/forums/en/blend/threads to see if there is anything wrong in your original code.

    For the other issue caused by subfolder, I think it's a VisualStudio issue.


    Min Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 14, 2013 3:17 AM
  • Well, curiouser and curiouser....

    Changing from BlendEmbeddedFont to Resource didn't fix anything for me, either.

    I think we can elminate the two-dictionary indirection from the equation. I get exactly the same results if I turn the keyed resource to an implicit resource and remove the second resource dictionary.

    I thought I'd try taking Blend out of the equation completely, so I created (yet another) repro project, created a Fonts directory and copied in BuxtonSketch.ttf. Set the Build action to "Resource" in the Properties Window.

    It's picking up the font size from the implicit style, but it doesn't display the font at runtime OR design-time. (I vaguely remember that's why I picked up the habit of embedding fonts in Blend a couple of years ago. Do what you know works instead of spending time figuring out what should but doesn't. Man I can be lazy sometimes.)

    Could it possibly be a difference in our VS builds? I'm running 11.0.51106.01 Update 1 and NF version 4.5.50709.

    Min Zhu, I really do appreciate all the time you're spending withi this.


    Rebecca M. Riordan

    Thursday, February 14, 2013 1:16 PM
  • Hi Rebecca,

    I was running your code on 11.0.50727.1 RTMREL. Maybe that makes a difference.


    Min Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, February 15, 2013 1:46 AM
  • Hi Rebecca,

    I tried it on another machine with Update 1 installed. I re-build the solution and it still works.

    Here is the project I used.

    https://skydrive.live.com/#cid=14362542B2FD72F8&id=14362542B2FD72F8%21229

    Does it work on your side?


    Min Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, February 15, 2013 3:01 AM
  • Ah, yes, it does. That's very good news, isn't it? Means it isn't some bizarre thing wrong with the Registry on my computer or something.

    I'll go line by line through the your project and mine to see if I can spot the difference. I'll keep you posted.

    Again, I do truly appreciate all the effort you're putting in on this Min Zhu. Most people would have just said "can't repro" and left me to my own devices by now.


    Rebecca M. Riordan

    Sunday, February 17, 2013 1:40 PM
  • My pleasure.

    Min Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 18, 2013 2:59 AM
  • <RANT>

    Well, after duplicating my results, they just closed the bug as "by design" on Connect. The workaround they suggest (which doesn't work) is to embed, un-embed, and then re-embed in Blend.

    By design??? Seriously??? They meant for it to work that way?

     </RANT>


    Rebecca M. Riordan


    Thursday, February 21, 2013 9:38 PM
  • Hi Rebecca M. Riordan,

    I think you can try Update 2 CTP, and reply the connect post if the issue presists.

    Best regards,


    Min Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, February 22, 2013 1:03 AM
  • Yes, the problem appears to be fixed in Update 2 CTP.

    When I worked for Microsoft, "By Design" was sometimes a euphemism for "yeah, we know, but it's too hard/too expensive/not important enough and we're not going to fix it", but never meant "fixed in the next update".

    Oh, well. The important thing is that it's working now, and I can start making progress with my project again.

    Again, Min Zhu, I really appreciate your help. You've been a real scout.


    Rebecca M. Riordan

    Friday, February 22, 2013 2:06 PM