Recently I need to realize a WPF project with a google font named Roboto.
Then I searched on the Internet to find some ways.
There were many ways to add it in my project, so I decided to try them all, especially those which was voted.
Firstly, I downloaded Toboto Font from google.
Secondly, I added a Toboto-Regular.ttf to Resources.resx, and change the Build to 'Resource'.
At last, I added some labels in a UserControl.xaml to test them.
here is the code:
<StackPanel>
<Label x:Name="label1" Content="Maintenance" FontFamily="/myAPP1;component/Resources/#Roboto" FontSize="16"/>
<Label x:Name="label2" Content="Maintenance" FontFamily="pack://application:,,,/Resources/#Roboto" FontSize="16"/>
<Label x:Name="label3" Content="Maintenance" FontFamily="Roboto-Regular" FontSize="16"/>
<Label x:Name="label4" Content="Maintenance" FontFamily="Roboto" FontSize="16"/>
<Label x:Name="label5" Content="Maintenance" FontFamily="./Resources/#Roboto" FontSize="16"/>
<Label x:Name="label6" Content="Maintenance" FontFamily="Arial" FontSize="16" />
<Label x:Name="label7" Content="Maintenance" FontSize="16" />
</StackPanel>
label1 font was selected from Property-Text-FontFamily-Roboto, it wasn't myself coding. label2-5 were the ways I found on the internet. label6&7 were put there as contrasts.
and soon I found label1&2 were the same, label3-5 were the same, label6&7 were just what they should be.
here is the image:
Label1-7 image
then I thought what exactly the FontFamily label3-5 were? Were they Roboto-Light? so I add Roboto-Light.ttf to my resources and selected from Property again, as you can imagine, it wasn't the same like label3-5.
here is the code:
<Label x:Name="label8" Content="Maintenance" FontFamily="/myAPP1;component/Resources/#Roboto Light" FontSize="16" />
here is the image:
Labels with fontfamily image
To figure it out, I post the question here, waiting for your answers. Thanks a lot!
Related
I'm trying to localize label with underscore helper (Alt). This example works fine but without localization.
Without localization:
<Label Content="_Name: "
Target="{Binding ElementName=TextBoxName}" />
I want something like that:
<Label Content="{x:Static loc:Localization.Name}"
ContentStringFormat=" _{0}"
Target="{Binding ElementName=TextBoxName}" />
Any ideas? Thanks
We have an Intermec touchscreen terminal (OS: Win7).
We use an application on it that uses an on-screen keyboard stored in xaml files (VTFKey, VTKey, VTKeyCaps, VTKeyShifted, VTKeyShiftedCaps).
I pasted the code from VTKey.xaml for the buttons that toggle between keyboard panels (the xaml files mentioned above):
<Button Canvas.Top="105.545" Height="49.995" Width="125" Command="{Binding Path=PressAndRelease}" CommandParameter="VK_CAPITAL" Content="Cap" />
<Button Canvas.Left="724" Canvas.Top="208.692" Height="50" Width="90" Command="{Binding Path=PressAndRelease}" CommandParameter="VK_TOGGLE" Content="Toggle" />
<Button Style="{DynamicResource ShiftKey}" Canvas.Left="836.583" Canvas.Top="156.651" Height="50" Width="163.317" Command="{Binding Path=PressAndHold}" CommandParameter="RSHIFT" Content="Shift" />
My question would be how do these commands (VK_CAPITAL, VK_TOGGLE, RSHIFT) know which xaml file to change to?
How could I create a custom keyboard consisting of 6 customized panels(xaml files)? Is it even possible?
Thank you!
My question would be how do these commands (VK_CAPITAL, VK_TOGGLE, RSHIFT) know which xaml file to change to?
You have XAML for the following three Buttons:
<Button Canvas.Top="105.545" Height="49.995" Width="125"
Command="{Binding Path=PressAndRelease}" CommandParameter="VK_CAPITAL"
Content="Cap" />
<Button Canvas.Left="724" Canvas.Top="208.692" Height="50" Width="90"
Command="{Binding Path=PressAndRelease}" CommandParameter="VK_TOGGLE"
Content="Toggle" />
<Button Style="{DynamicResource ShiftKey}" Height="50" Width="163.317"
Command="{Binding Path=PressAndHold}" CommandParameter="RSHIFT"
Content="Shift" />
Note the Command property... this is the name of the ICommand instance that performs the functionality for each Button. Two of these Buttons use the PressAndRelease Command. In this case, the CommandParameter is also used... inside the PressAndRelease Command code, you would probably see something like this:
if (parameter == "VK_CAPITAL") LoadVkCapitalView();
...
else if (parameter == "VK_TOGGLE") LoadVkToggleView();
As for the last part of your question, you'll have ask a more precise question for me to be able to answer it.
I am playing about with WPF and databinding a Label control's content:
<Label Content="{Binding Name}" />
This works a treat, however I'd like to get some text in there at design time so I can see the label. Anyone know how to do this, seems it should be simple.
Thanks
TJ
Try this:
<Label Content="{Binding Name, FallbackValue='Text'}" />
I have a WPF conundrum. I want some text to look like this:
Enter this preparer's info:
[ComboBox]
Alt+E is the access key that focuses the ComboBox, and when Alt is pressed, the E in the text should be underlined.
I can get the access key to work easily:
<Label Target="{Binding ElementName=PreparerComboBox}">
_Enter this preparer's info:</Label>
But then "preparer's" can't be bold because a Label doesn't support Runs (as far as I can tell).
I can do the bolding easily in a TextBlock:
<TextBlock>Enter this <Bold>preparer's</Bold> info:</TextBlock>
But there's no access key defined, so I tried adding my AccessText inside the TextBlock:
<Label Target="{Binding ElementName=PreparerComboBox}">
<TextBlock>
<AccessText>_Enter</AccessText> this <Bold>preparer's</Bold> info:
</TextBlock>
</Label>
But then the AccessText doesn't line up properly with the rest of the text in the TextBlock, and Margin doesn't seem to have any effect on it.
Example:
The best I've come up with so far is this monstrosity:
<Label Target="{Binding ElementName=PreparerComboBox}">
<WrapPanel>
<AccessText>_E</AccessText>
<TextBlock>nter this <Bold>preparer's</Bold> info:</TextBlock>
</WrapPanel>
</Label>
What am I missing here? Seems like there has to be an easier way.
Didn't change much but how about
<Label Target="{Binding ElementName=PreparerComboBox}">
<StackPanel Orientation="Horizontal">
<AccessText>_Enter</AccessText>
<TextBlock xml:space="preserve"> this <Bold>preparer's</Bold> info:</TextBlock>
</StackPanel>
</Label>
I'm hoping this will be my last question today. I'm in a hurry and google is not helping much (that or I'm searching the wrong places).
I created some custom properties and behaviors so my RadioButtons can alter my labels Content and the mask of my TextBoxes.
I could pass a String as a property, but how do I pass another control as a property? (AdjustedLabel is of type Label)
<RadioButton i:CPF_CNPJAdjustBehavior.LabelContent="Apple" i:CPF_CNPJAdjustBehavior.AdjustedLabel="??????????" Content="CPF" Height="16" HorizontalAlignment="Left" Margin="30,216,0,0" Name="radioButton1" VerticalAlignment="Top" GroupName="a" IsChecked="True">
<int:Interaction.Behaviors>
<i:CPF_CNPJAdjustBehavior/>
</int:Interaction.Behaviors>
</RadioButton>
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="20,81,0,0" Name="MyLabel" VerticalAlignment="Top" />
What do I have do write in "?????????" to set AdjustedLabel to the label named "MyLabel" ?
Thanks in Advance
Clark
AdjustedLabel="{Binding ElementName=MyLabel}" will do what you're searching for.
Consider reading some documentation for getting started with WPF, Bindings, Dependency Properties and XAML syntax. You could start with XAML Syntax In Detail, Dependency Properties Overview and Data Binding Overview.