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
Related
When using a string value as Content of a ContentControl (like Label), using an _ inside the string allows using the following letter as access key, like this:
<Label Content="Text with _access key"/>
or even
<Label Content="{Binding Text}"/>
if Text is a string property containing an _.
However, when using ContentStringFormat which contains the _, it doesn't work any more:
<Label Content="{Binding Value}" ContentStringFormat="_Formatted value {0}"/>
I have seen in the debugger that no AccessText is used in this case.
As a workaround, I have used AccessText explicitly:
<Label>
<AccessText Text="{Binding Value, StringFormat=_Formatted value {0}"/>
</Label>
It works that way but I still want to know why it doesn't when using ContentStringFormat.
Maybe This topic will give you some insight about the AccesText.
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!
Imagine I have a simple DataField in my Silverlight app. something like this:
<toolkit:DataField Label="This is my test label:">
<TextBox ... etc... />
</toolkit:DataField>
Is it possible to style the label in above example so that only the word "test" is bold?
you can use Run tag inside a textblock tag like this :
<toolkit:DataField >
<toolkit:DataField.Label>
<TextBlock >This is my <Run FontWeight="Bold">test</Run>label</TextBlock>
</toolkit:DataField.Label>
<TextBox ... etc... />
</toolkit:DataField>
i hope that it fixe your pb.
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>