Click here to Skip to main content
15,891,372 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to dynamically load assembly and dependencies from file path. Pin
Eddy Vluggen8-Sep-20 10:04
professionalEddy Vluggen8-Sep-20 10:04 
GeneralRe: How to dynamically load assembly and dependencies from file path. Pin
koirat8-Sep-20 12:25
koirat8-Sep-20 12:25 
QuestionCreate a Multi-Layer Data Model from a MySQL Query Pin
mjeeves7-Sep-20 8:25
mjeeves7-Sep-20 8:25 
AnswerRe: Create a Multi-Layer Data Model from a MySQL Query Pin
mjeeves7-Sep-20 8:43
mjeeves7-Sep-20 8:43 
GeneralRe: Create a Multi-Layer Data Model from a MySQL Query Pin
Richard MacCutchan7-Sep-20 9:27
mveRichard MacCutchan7-Sep-20 9:27 
GeneralRe: Create a Multi-Layer Data Model from a MySQL Query Pin
mjeeves7-Sep-20 9:44
mjeeves7-Sep-20 9:44 
GeneralRe: Create a Multi-Layer Data Model from a MySQL Query Pin
Richard Deeming7-Sep-20 22:34
mveRichard Deeming7-Sep-20 22:34 
QuestionProblem showing a symbol from a custom font Pin
Mc_Topaz6-Sep-20 21:18
Mc_Topaz6-Sep-20 21:18 
I have a custom font. The font contains symbols at specific addresses. I want to display one of the symbols in a TextBlock.

The font (ttf-file) is located in my applications's folder: Fonts.
I have included the font in the application and set the BuildAction to Resource.

I have verified the font's name (not file name) to reference it in my code.
I have verified which "address" the symbol should be fetched from in the font.

I have tried this both in XAML and with C#. But it won't work.

XAML
<Window x:Class="Main.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Main"
    mc:Ignorable="d"
    Loaded="Window_Loaded"
    Title="MainWindow" Height="450" Width="800">

    <Window.Resources>
        <Style x:Key="Foo">
            <Setter Property="TextElement.FontFamily" Value="pack://application:,,,/Main;component/Fonts/#MyFont" />
        </Style>
    </Window.Resources>

    <StackPanel Orientation="Vertical">
        <TextBlock Text="&#x E905;" Style="{StaticResource Foo}" />
        <TextBlock FontFamily="Segoe MDL2 Assets" Text="&#x E777;" />
        <TextBlock x:Name="txt1" />
        <TextBlock x:Name="txt2" />
    </StackPanel>
</Window>
Notice: Never mind the space in the middle of "address" for the first and second TextBlock. The code-view here at CodeProject failes to display the address. It tries, and fails, to fetch the correct symbols by that address - if I remove the space in the addresses...

C#
Here is the handler for the Loaded event:
C#
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    txt1.FontFamily = new FontFamily("pack://application:,,,/Main;component/Fonts/#MyFont");
    txt1.Text = "\xe905";

    txt2.FontFamily = new FontFamily("Segoe MDL2 Assets");
    txt2.Text = "\xe7777";
}
Result
The result are displayed in the four TextBlocks. From top to bottom:

* First: This fails. I get an empty rectangle, like these rectangles.
* Second: This line works. You should be able to copy this line into your own application with success.
* Third: Same as the first TextBlock. An empty rectangle.
* Forth: This "works". I get the correct symbol as well as an empty rectangle.


What could be the problem?
AnswerRe: Problem showing a symbol from a custom font Pin
Richard Deeming6-Sep-20 23:04
mveRichard Deeming6-Sep-20 23:04 
AnswerRe: Problem showing a symbol from a custom font Pin
Mc_Topaz6-Sep-20 23:54
Mc_Topaz6-Sep-20 23:54 
GeneralRe: Problem showing a symbol from a custom font Pin
Gerry Schmitz7-Sep-20 7:37
mveGerry Schmitz7-Sep-20 7:37 
GeneralRe: Problem showing a symbol from a custom font Pin
Mc_Topaz7-Sep-20 22:13
Mc_Topaz7-Sep-20 22:13 
AnswerRe: Problem showing a symbol from a custom font Pin
Mc_Topaz7-Sep-20 23:52
Mc_Topaz7-Sep-20 23:52 
QuestionDebug does not stop on errors. Pin
MAW306-Sep-20 15:27
MAW306-Sep-20 15:27 
AnswerRe: Debug does not stop on errors. Pin
Sandeep Mewara6-Sep-20 19:09
mveSandeep Mewara6-Sep-20 19:09 
AnswerRe: Debug does not stop on errors. Pin
OriginalGriff6-Sep-20 20:32
mveOriginalGriff6-Sep-20 20:32 
SuggestionRe: Debug does not stop on errors. Pin
Richard Deeming6-Sep-20 22:38
mveRichard Deeming6-Sep-20 22:38 
GeneralRe: Debug does not stop on errors. Pin
OriginalGriff6-Sep-20 22:51
mveOriginalGriff6-Sep-20 22:51 
QuestionChanging Caption in dt Pin
MAW306-Sep-20 15:22
MAW306-Sep-20 15:22 
AnswerRe: Changing Caption in dt Pin
OriginalGriff6-Sep-20 20:45
mveOriginalGriff6-Sep-20 20:45 
QuestionCan a button in a simple html-document somehow call a (clientside) C# method? Pin
arnold_w5-Sep-20 0:12
arnold_w5-Sep-20 0:12 
AnswerRe: Can a button in a simple html-document somehow call a (clientside) C# method? Pin
OriginalGriff5-Sep-20 0:30
mveOriginalGriff5-Sep-20 0:30 
GeneralRe: Can a button in a simple html-document somehow call a (clientside) C# method? Pin
arnold_w5-Sep-20 0:36
arnold_w5-Sep-20 0:36 
GeneralRe: Can a button in a simple html-document somehow call a (clientside) C# method? Pin
OriginalGriff5-Sep-20 0:54
mveOriginalGriff5-Sep-20 0:54 
AnswerRe: Can a button in a simple html-document somehow call a (clientside) C# method? Pin
Gerry Schmitz5-Sep-20 3:50
mveGerry Schmitz5-Sep-20 3:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.