-
Nov 4th, 2016, 09:01 AM
#1
Thread Starter
Junior Member
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>
-
Nov 4th, 2016, 10:32 AM
#2
Re: How to initialize a fontpicker?
Thread moved to WPF, since that's what it appears to be. If that isn't correct, please let me know.
My usual boring signature: Nothing
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|