Can't use custom font on my app - c#

I downloaded a font, and I created a folder Fonts inside the Assest in my project and used the following XAML code to set the font.
<TextBlock HorizontalAlignment="Left"
Height="107"
Margin="154,75,0,0"
TextWrapping="Wrap"
Text="Brain Train"
VerticalAlignment="Top"
Width="310"
FontSize="60"
FontFamily="./Assets/Fonts/Foxes In Love.ttf#Foxes In Love"
FontWeight="Thin"
Grid.RowSpan="2" />
In the Designer, when I add the Upper XAML Code, the font changes but when I run the app the font is set to default (not the Custom).
Why?

MAKE small changes in your path according to this link
click here
<TextBlock HorizontalAlignment="Left" Height="107" Margin="154,75,0,0"
TextWrapping="Wrap" Text="Brain Train" VerticalAlignment="Top"
Width="310" FontSize="60"
FontFamily=".\Fonts\Foxes In Love.ttf#Foxes In Love" FontWeight="Thin" Grid.RowSpan="2"/>

Related

Mouse events not firing in Windows WPF

I have a simple WPF application
<Grid>
<Border BorderBrush="Black" BorderThickness="1"
HorizontalAlignment="Left" Height="388" Margin="10,10,0,0" VerticalAlignment="Top" Width="329"/>
<Image x:Name="PreviewImg" HorizontalAlignment="Left" Height="400" Margin="10,10,0,0" VerticalAlignment="Top" Width="329" MouseDown="PreviewImgMouse" AllowDrop="True" PreviewMouseWheel="PreviewImg_PreviewMouseWheel" MouseEnter="Entered" Focusable="True"></Image>
<Label Content="Matched Products" HorizontalAlignment="Left" Margin="344,10,0,0" VerticalAlignment="Top" Width="290"/>
<Label Content="Unknown Products" HorizontalAlignment="Left" Margin="661,10,0,0" VerticalAlignment="Top" Width="290"/>
<TextBlock x:Name="MatchedProducts" HorizontalAlignment="Left" Margin="349,36,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="362" Width="295"/>
<TextBlock x:Name="UnknownProducts" HorizontalAlignment="Left" Margin="666,36,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="362" Width="295"/>
<Grid HorizontalAlignment="Left" Height="50" Margin="10,410,0,0" VerticalAlignment="Top" Width="957">
<Button x:Name="FinalizeBtn" Content="Finalize" HorizontalAlignment="Left" Margin="826,10,0,0" VerticalAlignment="Top" Width="120" Height="30"/>
<Button x:Name="NewEntryBtn" Content="Create new entry" HorizontalAlignment="Left" Margin="701,10,0,0"
VerticalAlignment="Top" Width="120" Height="30"/>
<Button x:Name="FreeBtn" Content="Free Button" HorizontalAlignment="Left" Margin="576,10,0,0" VerticalAlignment="Top" Width="120" Height="30"/>
</Grid>
</Grid>
All the events defined under the Image component are not firing, I tried all of googles first page searches, but none of them work.
I read about the difference of Routed events in my application both MouseDown and PreviewMouseDown should work.
The only thing that can block the image is Border component, but I did try without it and still nothing, and since it is declared first the image should overlay it...?
All function names are correct since they were automatically generated.
I can paste in the .cs file if it can help.
Thanks
E1: Somehow it works now, but I have no idea what fixed it...
One change I did was mode the image inside the border:
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="388" Margin="10,10,0,0" VerticalAlignment="Top" Width="329">
<Image x:Name="PreviewImg" Height="400" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Center" Width="329" MouseDown="PreviewImgMouse" AllowDrop="True" PreviewMouseWheel="PreviewImg_PreviewMouseWheel" MouseEnter="Entered" Focusable="True"/>
</Border>
But I can't image that this fixed it.
You need to define a source for your image like <Image Source="image.jpg". Without the image the events will not fire.
For advanced users
Use a Button styled as an Image, see #Richard's answer with WPF Image Control with Click event
For beginners
The Image component needs a source to fire events as posted by #Örvar. Adding a transparent source is the solution, although a hacky one.
One way of achieving what you want is to place the image in a button and removing the button styles. There is an excellent example here:
WPF Image Control with Click Event

How do i set the background image of a button in a WPF Application?

I cannot find the background-Image Property in the properties panel of the button, I have the images stored for each button in the root directory of my solution as Jpegs, the project is a WPF and I don't know how to set the image in the XAML or C# code. I am developing in Visual Studio 2017 Community Edition
All problems I have seen before are for different versions of Visual Studio, so I can't find the answer
*edit - i am trying to change the background image of a button at design time in the XAML editor, not create an onclick button to change a background image. So if i have this button in XAML:
<Button x:Name="keyBtn"
Content="Keyboard/Mouse"
HorizontalAlignment="Left" VerticalAlignment="Top"
Width="400" Height="800" FontFamily="Verdana"
Background="#FFB41717"
Margin="0,-31,0,0"/>
Which Part should I refer to in the ".background" property?
It is probably easier than you think..
Try this after you add the image to your project.
<Button x:Name="keyBtn"
HorizontalAlignment="Left" VerticalAlignment="Top"
Width="400" Height="800" FontFamily="Verdana"
Background="#FFB41717"
Margin="0,-31,0,0">
<Image Source="myImage.png" />
</Button>
Note that you need to remove the content since now the image is the content.
If you wish the text as well - you can try this:
<Button x:Name="keyBtn"
HorizontalAlignment="Left" VerticalAlignment="Top"
Width="400" Height="800" FontFamily="Verdana"
Background="#FFB41717"
Margin="0,-31,0,0">
<Grid>
<Image Source="myImage.png" Stretch="Fill" />
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="Keyboard/Mouse" />
</Grid>
</Button>
And there is another option - which might be exactly what you are looking for:
<Button x:Name="keyBtn"
Content="Keyboard/Mouse"
HorizontalAlignment="Left" VerticalAlignment="Top"
Width="400" Height="800" FontFamily="Verdana"
Margin="0,-31,0,0">
<Button.Background>
<ImageBrush ImageSource="myImage.png" Stretch="Fill" />
</Button.Background>
</Button>
But in that last option - you will have to remove the Background color as it is being replaced by the image.

Setting image's build action property

I have simple problem. I want to add image to buttons and there is one case I can't manage. In designer everything works properly, but in debug mode there is no trace of a picture inside the button. I read that I have to set Build Action property of the image to "Recourses" or "Content" but I don't have these pictures in Solution Explorer, exactly I can see them when I click "Show All Files but they have strange icon not as the one image which I can normally see in Solutions Explorer and no Build Action property.
Am I supposed to add images in different way?
<Button x:Name="loadButton" HorizontalAlignment="Left" Margin="955,0,0,443" Style="{DynamicResource SimpleButton}" VerticalAlignment="Bottom" Width="29" Height="27" FontFamily="Courier New" FontWeight="Bold" Click="loadButton_Click" Background="{x:Null}" BorderBrush="{x:Null}">
<StackPanel Orientation="Horizontal">
<Image x:Name="Load" Source="open-map.png"/>
</StackPanel>
</Button>
<CheckBox x:Name="mode" Content="Tryb tworzenia" HorizontalAlignment="Left" Margin="30,292,0,0" VerticalAlignment="Top" FontSize="18.667" Foreground="#FFAC3333" FontFamily="Courier New" IsChecked="True"/>
<Button x:Name="button1_Copy" HorizontalAlignment="Left" Margin="912,0,0,443" Style="{DynamicResource SimpleButton}" VerticalAlignment="Bottom" Width="29" Height="27" FontFamily="Courier New" FontWeight="Bold" Click="button1_Copy_Click" Background="{x:Null}" BorderBrush="{x:Null}">
<StackPanel Orientation="Horizontal">
<Image x:Name="Save" Source="save-icon.png"/>
</StackPanel>
</Button>
Thank in advanced
The files like open-map.png are not part of the C# project so you can't set any properties. Right click on the C# project and add the file to the project, then you'll be able to set its properties.

how to Give color of a ListBox in windows phone 8 when Backgroud is white? with a image Button

i am new to windows phone development,..
So i am preparing an application in that i given Background Color as white for every page..
in my app i added a search so that user can search data using two text Box..
In that I have given Bg color as white and foreground Color as black.. in that TextBlock is Viable But TextBox are not Visable they are mixing in background...
This is My xaml fiel..
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Margin="10,114,10,311">
<TextBlock Text="Enter Name"
TextWrapping="Wrap"
Tap="TextBlock_Tap"
Foreground="Black" />
<TextBox x:Name="Enter Name Field"
GotFocus="TextBox_GotFocus"
LostFocus="TextBox_LostFocus"
Foreground="RosyBrown" Height="46" Margin="27,0,56,0" />
<TextBlock Text="Enter A Model number"
TextWrapping="Wrap"
Tap="TextBlock_Tap"
Foreground="Black"/>
<TextBox x:Name="Enter A Model number Field"
GotFocus="TextBox_GotFocus"
LostFocus="TextBox_LostFocus"
Foreground="RosyBrown" Height="46" Margin="27,0,56,0" />
</StackPanel>
</Grid>
Sorry i want to add a Image Button also i tried....
i want it like this
This may help you.
<Grid Grid.Row="1" Background="White">
<StackPanel Margin="10,114,10,311">
<TextBlock Text="Enter Name"
TextWrapping="Wrap"
Tap="TextBlock_Tap"
Foreground="Black" />
<TextBox x:Name="Enter Name Field"
GotFocus="TextBox_GotFocus" BorderBrush="Gray" BorderThickness="2"
LostFocus="TextBox_LostFocus"
Foreground="RosyBrown" Height="46" Margin="27,0,56,0" />
<TextBlock Text="Enter A Model number"
TextWrapping="Wrap"
Tap="TextBlock_Tap"
Foreground="Black"/>
<TextBox x:Name="Enter A Model number Field"
GotFocus="TextBox_GotFocus"
LostFocus="TextBox_LostFocus" BorderBrush="Gray" BorderThickness="2"
Foreground="RosyBrown" Height="46" Margin="27,0,56,0" />
<Image Height="40" Width="150" Source="your image path" Tap="Image_tap" />
</StackPanel>
</Grid>
add Background="Black" (or whatever color you want) in all your TextBox.
For that what you have shown use BorderBrush="Black", decrease the border thickness if you need to. Yes, you can add a image button, use a image as your button background.
<Button>
<Button.Background>
<ImageBrush Source="your_file.jpg" Stretch="Fill"/>
</Button.Background>
</Button>
Note: It is not a good idea to write x:Name value with spaces. what you write in x:Name ultimately become a variable name of type TextBox (in this case) and c# doesn't permit variable name with space, So just delete the spaces and use x:Name="Enter_A_Model number_Field" or simply x:Name="EnterAModelNumberField"
Use your textbox surrounded with border, since you are using a white background.I think below code may help you to get an idea.
<Border BorderThickness="1" Grid.Row="2" Name="brdUsrName" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="60" Background="Black">
<TextBox Name="txtUserName" Margin="-10,-10,-10,-10" />
</Border>

Image inside textblock c# windows 8

I'm trying to put an imagine inside a textblock inside a scrollviewer for my textblock. What I'm trying to accomplish is to have it as a background for my textblock and this is not even running. It compiles but it crashes.
<Image Source="Assets\picture.png" Margin="564,196,659,292" Grid.Row="1"/>
<ScrollViewer Height="645" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" Margin="330,113,0,0" Name="scrollViewer1" VerticalAlignment="Top" Width="627" Grid.RowSpan="2">
<TextBlock x:Name="tbl" VerticalAlignment="Top" Width="627" TextWrapping="Wrap" Foreground="White" FontFamily="Times New Roman" FontSize="22" >
</TextBlock>
I get to see the image on the designer but it crashes... Thanks!
Try this :
Using Grid or canvas we can place elements one over the other
<ScrollViewer x:Name="ScrollViewer">
<Grid>
<Image Source="Assets\picture.png" />
<TextBlock x:Name="TextBlock" />
</Grid>
</ScrollViewer>

Categories

Resources