Quantcast
Viewing all articles
Browse latest Browse all 256

How to initialize a fontpicker?

Hi,

i have recently made a fontpicker, mostly for practice. I have used an example which uses databinding as a basis to build on.
Now the problem i have is this:
When i open the fontpicker for the second time, i want the font that was chosen the first time to be visible. I am trying to do this by passing values to the FontInfo property of the dialog. Unfortunately i can't apply those values, because the properties of the preview textbox are all bound. Setting these properties to the values in FontInfo will overwrite these bindings. How do i get around this problem?
(Is there any way to also bind the properties of txtPreview to variables in the context?)

i.e. the following does not work:
Code:

Dim dlgFont As New FontPickerDialog
  dlgFont.font = FontInfo.GetFontInfo(txtWatermark)
  If (dlgFont.ShowDialog) Then
      fntSelected = dlgFont.font
      If (fntSelected IsNot Nothing) Then
          fntSelected.ApplyTo(txtWatermark)
            DisplayPreview()
      End If
  End If

The bindings i'm talking about:"
Code:

<TextBox Name ="txtPreview"  AcceptsReturn="true" Padding="20"
                FontSize="{Binding ElementName=fontSizeSlider, Path=Value}"
                FontFamily="{Binding Source={StaticResource familyCollection},Path=Source}"
                FontWeight="{Binding ElementName=familyTypefacesList,Path=SelectedItem.Weight}"
                FontStretch="{Binding ElementName=familyTypefacesList,Path=SelectedItem.Stretch}"
                FontStyle="{Binding ElementName=familyTypefacesList,Path=SelectedItem.Style}"
                Foreground="{Binding ElementName=colorPicker, Path=SelectedColor, Converter={StaticResource ColorToBrushConverter}}"
                Opacity="{Binding ElementName=nudOpacity, Path=Value, Converter={StaticResource OpacityConverter}}"
                TextAlignment="Center" TextWrapping="Wrap" Grid.Row="0"
                TextBlock.LineHeight="{Binding ElementName=txtPreview, Path=FontSize, Converter={StaticResource LineHeightConverter}}"
                TextBlock.LineStackingStrategy="BlockLineHeight">
                The quick brown fox jumps over the lazy dog
                </TextBox>


Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>