I am loading a .rtf file into a WPF Rich TextBox and my images that have links are getting this underline property added. I do not want the underline and cant seem to get rid of it.
public MainWindow()
{
InitializeComponent();
Assembly assembly = Assembly.GetExecutingAssembly();
Stream s = assembly.GetManifestResourceStream("WPFRichTextIssue.Sigs.MSC.rtf");
using (s)
{
TextRange TR = new TextRange(RTB.Document.ContentStart, RTB.Document.ContentEnd);
TR.Load(s, DataFormats.Rtf);
}
}
I have tired to find the underlined images with
if (TR.GetPropertyValue(Inline.TextDecorationsProperty) == TextDecorations.Underline)
{
}
else
{
// Do something
}
But the Image is not Inline.Text so it does not find it... Any help would be great.
I also thought maybe i could overwrite the Rich Textbox default functionality that causes the underline of links but all i can seem to find to make that change is to the Inline Text nothing for the images and the images are not affected.
The only other option i can think is if there was a way to change the .rtf file to make sure it did not have any underline attributes but unless I am missing something that does not seem to help either.
Entire VS 2012 project issue sample... Download Project
thanks
Looking in your XAML, just after the RTB opening tag that looks something like this:
<RichTextBox x:Name="RTB_Reply" HorizontalAlignment="Left" Height="157" Margin="302,338,0,0" VerticalAlignment="Top" Width="488" IsReadOnly="True">
Paste this:
<RichTextBox.Resources>
<Style TargetType="{x:Type Hyperlink}">
<Setter Property="TextDecorations" Value="{x:Null}"/>
</Style>
</RichTextBox.Resources>
done deal. =D
Related
I am trying to use a font called Suisse Int'l Cond which is located in my project as fonts/SuisseIntlCond-Regular.otf and a build action of Resource
Other examples of OTF font in the project work without issue.
Works:
<Setter Property="FontFamily" Value="fonts/moon.otf #moon"/>
Dosn't Work:
<Setter Property="FontFamily" Value="fonts/SuisseIntlCond-Regular.otf #Suisse Int'l Cond"/>
My guess is it might be an issue with the ' char in the name or something wrong with the font itself but I have been unable to confirm either of these as the issue.
Importing and then exporting the font using Glyphr Studio resolves the issue even with keeping the same name.
How do I change a font's metadata (specifically a title)?
I'm trying to implement 2 different themes for a WPF Application. I found this excellent post by #bendewey:
"Can WPF themes be used to include multiple skins for an application that can be changed at runtime?"
And have used it to implement two themes. I have created two Resource Folders, Lets call them ResourcesTheme1 and ResourcesTheme2 and Two Xaml Resource Dictionary files (Style1.xaml & Style2.xaml) that have the styles.
With this I have been able to set the following styles:
In Style1.xaml
<Style x:Key="HomeViewBackGroundImage" TargetType="Image">
<Setter Property="Source" Value="/ResourcesTheme1/Background.png" />
</Style>
In Style2.xaml
<Style x:Key="HomeViewBackGroundImage" TargetType="Image">
<Setter Property="Source" Value="/ResourcesTheme2/Background.png" />
</Style>
And this has worked a treat for me (if there's a better way please feel free to suggest it).
No the problem I have is that within my mainPage xaml I want to put on a row of buttons and each button has it's own image that it get's from binding to an ObservableCollection. I would like the Binding to look into the correct resource folder, but don't know how to make it happen without writing code behind.
So what I have is the following Binding:
<Image Name="ContentImage" Source="{Binding ImageName}" Stretch="UniformToFill">
And the following code behind:
if (useTheme1)
{
imageName = "/PlayingWithThemes;component/ResourcesTheme1/" + imageFileName;
}
else
{
imageName= "/PlayingWithThemes;component/ResourcesTheme2/" + imageFileName;
}
Any thoughts on how I could make the source for the image something like:
Source="ResourceFoler + {Binding ImageName}"
Or is there something more generic than:
/PlayingWithThemes;component/ResourcesTheme1/"
That I could use.
Thanks in advance.
A
I have a problem with WPF. I need WPF only for changing font size. So, I want to make something like text editor but only with changing the Font Size. I need to have text box/ text block and a button ("Font Size") which when you click it opens a new textbox and you add the desire size of the text. After you add the number it binds it and applies it to the text.
I can not write the code and will be very grateful if someone helps me! Thanks in advance!
You can use the following :
Style TargetType="{x:Type Window}">
<Setter Property="FontSize" Value="15" />
/Style>
and then add the dynamic change :
Say, textbox1 is the textbox where you want to add size value..
TextBlock FontFamily="Arial" Text="Sample text" FontSize="{Binding TextSize}" />
or
Application.Current.MainWindow.FontSize = Textbox1.text.toInt32();
I would like to import custom fonts on my WPF application so that they work without having the client to install them.
All the answers I have found so far are in XAML, I would like to do it only in C#.
My fonts are in Resources/Fonts/.
I have already tried this :
Fonts.GetFontFamilies(new Uri("pack://application:,,,/Resources/Fonts/#"));
But it didn't work.
I did everything bluetoothfx said but it still did not work.
Then I changed the Build action of my fonts (it was to Content), to Embedded Resource, and it worked. Resource works also for me.
Thanks anyway.
I think the way that you are working will not work.
At first create a folder name fonts then Add the font to your project, change its Build Action to Content.
Now you need to find the internal name (Real name) of the font not the font-file name. You can have it by opening the font file and you can see it on top.
Now edit App.xaml
<Application.resources>
<style x:key="MYFONT_INTERNAL_NAME">
<setter property="TextElement.FontFamily"
value="pack://application:,,,/fonts/#MYFONT_INTERNAL_NAME" />
</style>
Now use it in your code like:
<TextBlock Style="{StaticResource MYFONT_INTERNAL_NAME}" FontSize="16" Text="Font Style" />
To know more search here:
http://www.alteridem.net/2014/02/24/custom-fonts-in-wpf-applications/
In a Windows Phone 8.1 WinRT app using c# in Microsoft Visual Studio, with the following code, how can I change the font size of the grid's children text blocks dynamically in the code behind?
<Grid Name="mainGrid">
<Grid.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="5"/>
<Setter Property="FontSize" Value="12"/>
</Style>
</Grid.Resources>
</Grid>
The idea is to let the user change the font size in the options screen, and then save it to local settings, and then change the display to match the font size.
The grid's children text blocks are added dynamically when the app is loaded, and I'm not asking how to load values from ApplicationData.Current.LocalSettings. I'm also aware that the styles and setters don't have any names yet, which could be filled in if needed.
I would like to avoid using a resource dictionary and data bindings if possible.
Can someone provide a simple code example to use in the code behind to change the font size?
Here is the way I used to change the style dynamically, but the resource dictionary would be involved.
private void changeSzie_Click(object sender, RoutedEventArgs e)
{
var dynamicStyle = new Windows.UI.Xaml.Style();
var targetType = typeof(Windows.UI.Xaml.Controls.TextBlock);
dynamicStyle.TargetType = targetType;
dynamicStyle.Setters.Add(new Setter(Windows.UI.Xaml.Controls.TextBlock.FontSizeProperty, int.Parse(textbox.Text)));
if (mainGrid.Resources.Keys.Contains(targetType))
{
mainGrid.Resources.Remove(targetType);
}
mainGrid.Resources.Add(targetType, dynamicStyle);
}