I've been trying to change the FontWeight of a single Label inside of a StackPanel of labels to no avail. In the example below, I try to change the FontWeight inline with the Label definition, but this does not work. I can't seem to change the FontWeight, FontSize, FontStyle, etc. I have been able to change the Foreground though.
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"
DataContext="{Binding Path=MyDataContext}" Grid.Column="1" Grid.Row="4" >
<Label Content="{Binding Path=Label1Content}" FontWeight="Bold"></Label>
<Label Content="{Binding Path=Label2Content}"></Label>
<Label Content="{Binding Path=Label3Content}" ContentStringFormat="c"></Label>
<Label Content="{Binding Path=Label4Content}" ContentStringFormat="c"></Label>
</StackPanel>
I have also tried creating a resource and using a style to do it and have tried changing the FontWeight using the code behind, neither worked.
Further looking in the Live Property Inspector, even though the Label was bold, there was a TextBlock inside that was not. Changing the labels to the following code fix this:
<Label>
<TextBlock Text="{Binding Path=Label1Content}" FontWeight="Bold"></TextBlock>
</Label>
Related
I am trying to put 2 label in stackpanel (Which is in grid) side by side but it's not wokring. the 2nd label come to the 2nd line.
I tried 2 textblock in content property but it doesn't work. I try settting Orientation and ContentAlignment mention in stackoverflow doesn't make any changes.
The first label is bold and another one is normal. Anyone have any idea how to make it work.
Here is the code.
<Label Style="{StaticResource FormHead}">
<Label.Content>
<TextBlock>aaa</TextBlock>
<TextBlock>bbb</TextBlock>
</Label.Content>
</Label>
You can simply do it as below :
<StackPanel Orientation="Horizontal">
<TextBlock>aaa</TextBlock>
<TextBlock>bbb</TextBlock>
</StackPanel>
Try this.
<Label>
<Label.Content>
<StackPanel Orientation="Horizontal">
<TextBlock>aaa</TextBlock>
<TextBlock>bbb</TextBlock>
</StackPanel>
</Label.Content>
</Label>
I have a simple XAML example:
<Grid>
<Button x:Name="button1" FontSize="28" FontWeight="Bold" FontStyle="Oblique" HorizontalContentAlignment="Center" Margin="296,142,296,249">
<TextBlock Width="Auto" Text="button" Padding="0" VerticalAlignment="Center"/>
</Button>
<Button x:Name="button2" Content="button" FontSize="28" FontWeight="Bold" FontStyle="Oblique" Margin="296,234,282,146" />
</Grid>
If height of any button will changed in design mode (or added and changed property Height in xaml), the part of last letter of text in textblocks will surprisingly cut from right side.
The error is only presents on oblique font style ('italic' or 'normal' looks good). Looks like text blocks have uncorrect calculated borders of width in this case.
It can be fixed by changing Padding property (Padding="0,0,6,0"). But it's not a good practice I think.
Could anyone advice how to show oblique fontstyle text correct?
I have a Label just displaying a title.
How can I justify the text? and how can I distribute the text? Can I use a label or do I have to use another control?
Label doesn't have any text alignment property, however TextBlock does have text alignment properties so you can use justify if that's what you're looking for:
<TextBlock TextAlignment="Justify" />
As Matt said you can only apply the Justify property on TextBlock, so the way to go is to put the TextBlock inside of the Label as below:
<Label
Grid.Row="2"
Grid.Column="2"
Grid.ColumnSpan="4"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontSize="26">
<TextBlock
TextWrapping="Wrap"
Text="Sample Text"
TextAlignment="Justify"/>
</Label>
The appeareance of my button is perfect if I define what the text is.
Working Image
<StackPanel Orientation="Horizontal">
<ContentControl ContentTemplate="{StaticResource Icons.Person}" Style="{StaticResource Icon}"/>
<TextBlock Text="PERSONS"/>
</StackPanel>
I want to set the text to be Binding to a variable but this Overlaps the image.
Appearance after Bindings
<StackPanel Orientation="Horizontal">
<ContentControl ContentTemplate="{StaticResource Icons.Person}" Style="{StaticResource Icon}"/>
<TextBlock Text="{Binding Persons"/>
</StackPanel>
Icon.xaml
<DataTemplate x:Key="Icons.Person">
<Viewbox>
<Path ......./>
</Viewbox>
</DataTemplate>
Path code is huge, if it's needed I'll upload it.
What I've tried is changing the Datatemplate to be only a ViewBox with a key, and change content control to be a stackpanel with a viewbox within it and the text box. Same effect would happen. May I ask how to fix this or what's an alternative to show my datatemplate/viewbox with a binding text field
I am looking for a correct way to enable text wrapping in the header of Pivot control in my WP8 application.
Here is the code:
<phone:Pivot Title="MY APPLICATION">
<phone:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" TextWrapping="Wrap"/>
</DataTemplate>
</phone:Pivot.HeaderTemplate>
<phone:PivotItem Header="very long item name">
<Grid/>
</phone:PivotItem>
</phone:Pivot>
As you can see the 'TextWrapping' property is explicitly set to 'Wrap', but I do not observe any wrapping whatsoever. Does anyone know the workaround?
You need to set the Width of TextBlock explicitly for TextWrapping to work.
<TextBlock Text="{Binding}" TextWrapping="Wrap" MaxWidth="400" Height="Auto"/>
Above works fine.