none
Strange bug on embedded font

    Question

  •  Hi folks

     I need a monospaced font on a row details view, so I embedded Consolas into the project. But then I recognized that the font was not used by some databound TextBlock's. After one hour of investigation I found a strange behavior in the font usage.


    Here the code:

               <data:DataGrid.RowDetailsTemplate>
    <DataTemplate>

    <Grid ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" >
    <Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <TextBlock Margin="5,0,5,0"
    Text="{Binding Path=querySeq}"
    TextWrapping="NoWrap" FontFamily="./Fonts/Fonts.zip#Consolas" VerticalAlignment="Center" HorizontalAlignment="Left" d:IsStaticText="True" FontSize="16"/>
    <TextBlock Margin="5,0,5,0"
    Text="{Binding Path=pattern}"
    TextWrapping="NoWrap" FontFamily="./Fonts/Fonts.zip#Consolas" VerticalAlignment="Center" Grid.Row="1" HorizontalAlignment="Left" d:IsStaticText="True" FontSize="16"/>
    <TextBlock Margin="5,0,5,0"
    Text="{Binding Path=matchSeq}"
    TextWrapping="NoWrap" FontFamily="./Fonts/Fonts.zip#Consolas" VerticalAlignment="Center" Grid.Row="2" HorizontalAlignment="Left" FontSize="16"/>
    <TextBlock Margin="5,0,5,0"
    Text="ABCDEFGHIJKLMNOPRSTUVWXYZ"
    DataTemplate>
    </data:DataGrid.RowDetailsTemplate>
    As you can see I included a dummy TextBlock in the  RowDetailsTemplate which will demonstrate the behavior. Each letter which appears in dummy TextBlock will also use the correct Consolas font in the databoubd TextBlocks.
    All letters are not in the dummy are using a fallback font in the databound TextBlock. So in this case Q will be not displayed in the Consolas font but in anothe font. I guess
    it has something to do with time point when the font is allocated.  
    So my current workarund will be a transparent dummy TextBlock with all letter I expect in the real TextBlocks. 
     
    Cheers
    Jan 
      
    Monday, October 27, 2008 3:54 PM