UWP PersonPicture control background not being set - xaml

PersonPicture is a control offered in Microsoft's Universal Windows Platform.
It looks great, which is why I'm trying to use it to display a user's initials with a background color.
The problem is that when I set the control's background to a color, the background is not changed on the display.
<PersonPicture Initials="JF"
Background="Red"/>
In the above code, the Background still remains the default, while everything else is updated.
Please if you have been able to set the background color, share how you've done it!

I found the template for the PersonPicture through this question: How to get all Controls' ControlTemplates Programmatically?(UWP)
The PersonPicture ignores its Background property and uses a couple of brushes that make up the colors of the control depending on Dark/Light theme and some hard coded values.
It draws an ellipse/circle and thus shows its container's color in the four corners.
Assuming you want to set the color in the square that contains the picture you could do this:
<Grid Background="Green">
<Grid HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Red">
<PersonPicture />
</Grid>
</Grid>
The first grid represents a page. The second grid tightly wraps around the PersonPicture:
Note how the personpicture is somewhat transparent and shows the color of the grid. The color that the template uses for the ellipse is #77FFFFFF
So you could take it a step further by adding an ellipse:
<Grid Background="Green">
<Grid HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Red">
<Ellipse Fill="White"/>
<PersonPicture />
</Grid>
</Grid>
This allows you to control the color of the picture somewhat by setting the color of the ellipse:
Do note that it still mixes the PersonPicture with the background so you cannot set it to black:
<Grid Background="Green">
<Grid HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Red">
<Ellipse Fill="Black" />
<PersonPicture />
</Grid>
</Grid>
Shows:
And finally, you could copy the template (see: How to get all Controls' ControlTemplates Programmatically?(UWP))
and adjust it to use the Background property.

Related

ItemControl background color

In a fresh Universal Windows Platform app, I am trying to set the Background of an ItemsControl. But it doesn't seem to do anything. The only changes I've made to the VS template are in MainPage.xaml, which now looks like this:
<Page
x:Class="UWPPlayground.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWPPlayground"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" x:Name="Hello">
<Grid Background="Blue">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*">
</ColumnDefinition>
<ColumnDefinition Width="*">
</ColumnDefinition>
</Grid.ColumnDefinitions>
<ItemsControl Grid.Row="0" Grid.Column="0" Width="60" Height="30" Foreground="Wheat" Background="White">
<TextBlock Text="Hello World!"></TextBlock>
<TextBlock Text="Can you see this?"></TextBlock>
</ItemsControl>
<Grid Grid.Row="0" Grid.Column="1" Background="Purple"></Grid>
</Grid>
</Page>
The result is shown below. The Foreground property of the ItemsControl seems to be working just fine, as the TextBlocks have wheat-colored text. Due to the small size of the control, the text is cut-off, as expected. The Background, however, is not visible. What am I missing?
ItemsControl inherits from Control, which defines lots of visual properties at the base class level which do not necessarily influence the appearance of the control directly. These properties are usually referenced via TemplateBindings in the ControlTemplate, which then gives rise to the desired appearance. Whether or not the template uses these properties determines whether or not they have any use at all.
You'll notice that changing a UserControl's background also does nothing (for the same reason mentioned above).
Non-control classes like Grid, Rectangle, Border (etc) do honor such properties out of the box, since these are the elements typically used in the templates of controls to produce a certain appearance.
The reason why ItemsControl-derived classes (like ListView) do honor the background property is because some root-level element in its template references the Background property (via TemplateBinding). ItemsControl on its own has no template.
I think the reason why the Foreground property works is because it will inherit its value from the parent. (Some dependency properties can inherit their values like this).
The easiest way to set a background for your ItemsControl would be to wrap it in a Border (or Grid, they're essentially the same now) and set a background brush on that instead.
I don't recommend you do what follows for your example, but this is what you would need to do if you wanted the Background property to work:
<ItemsControl Background="Red">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Grid Background="{TemplateBinding Background}">
<ItemsPresenter/>
</Grid>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>

How to change listpicker dropdown ItemTemplate background?

I have a Windows Phone 8 listpicker that I'm trying to change the background color of, however, it only seems to change the item background and not the dropdown box background as you can see in the screen capture. The dropdown box seems to be binded to the WP8 theme. How can I change the background of the entire dropdown box and not just each individual item?
<toolkit:ListPicker x:Name="BackgroundListPicker" Background="Black" ItemsSource="{Binding BackgroundsList}">
<toolkit:ListPicker.ItemTemplate >
<DataTemplate x:Name="BackgroundItemTemplate" >
<Grid HorizontalAlignment="Stretch" Background="Black" VerticalAlignment="Stretch" Margin="0,0,0,0">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding BackgroundThumb}" Width="30" Height="30" HorizontalAlignment="Left" />
<TextBlock Text="{Binding BackgroundName}" Foreground="White" Margin="12,0,0,0" HorizontalAlignment="Right"/>
</StackPanel>
</Grid>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
</toolkit:ListPicker>
So your issue was that you were attempting to apply an image to an item. When you needed to hit the control itself that the items populate via ItemsPresenter so by pulling out the default style template for the control, and either making a place to pass in your image for an instance, or placing one directly into the template itself. You get your resulting background image for the ListPicker background to fall behind the items populating it.
Glad you found your remedy! Cheers.

I cant place or set background or border of my user control

I've created a simple user control for my xaml project, but as you can see from my image i cant seem to be able to do certain things.
Ignore the red line, its the size of the control for illustrate its size.
It's placement should be middle of the screen:
<Client:TileMenu HorizontalAlignment="Center" VerticalAlignment="Center" Name="TileOverlayMenu" Background="Azure" BorderBrush="Aquamarine" BorderThickness="3" />
And as you see its background color should be "Azure" with a blueish border of 3.
Why is this?
In the background I have a Canvas:
<Grid x:Name="ContentPanel" Grid.Row="0" Margin="12,0,12,0">
<Canvas Name="GameCanvas">
<Canvas.RenderTransform>
<CompositeTransform x:Name="CanvasRenderTransform" />
</Canvas.RenderTransform>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragStarted="GestureListener_DragStarted" DragDelta="GestureListener_DragDelta" Tap="GestureListener_Tap" PinchStarted="GestureListener_PinchStarted" PinchDelta="GestureListener_PinchDelta"/>
</toolkit:GestureService.GestureListener>
</Canvas>
<Client:TileMenu HorizontalAlignment="Center" VerticalAlignment="Center" Name="TileOverlayMenu" Background="Azure" BorderBrush="Aquamarine" BorderThickness="3" />
</Grid>
As for my third problem, having the events in the canvas causes the Move slider to be interrupted, making me only able to push it a little each time :-/
In case TileMenu is a UserControl you would have to set these properties on the top level container in the UserControl's XAML as this defines the entire visual structure of the control.
You could bind to the appropriate values in the UserControl, however:
<UserControl x:Class="YourNamespace.TileMenu" ...
x:Name="tileMenu">
<Border BorderBrush="{Binding BorderBrush, ElementName=tileMenu}"
BorderThickness="{Binding BorderThickness, ElementName=tileMenu}">
<Grid>
...
</Grid>
</Border>
</UserControl>

RenderTransform occurs after EntranceThemeTransition on a TextBlock

I'm applying an EntranceThemeTransition animation to a TextBlock. The TextBlock has a style of PageHeaderTextStyle which has a RenderTransform in it. The issue I'm having is that the RenderTransform applies a Translation effect that doesn't actually render until after the animation is done playing. So, it looks weird because the animation scrolls the control in, and then suddenly the translation snaps the text in place. Does anyone know why this happens?
Is there a way to play the animation with the translation taken into account?
Transform:
<Setter Property="RenderTransform">
<Setter.Value>
<TranslateTransform X="-2" Y="8"/>
</Setter.Value>
</Setter>
TextBlock:
<TextBlock x:Name="pageTitle" Grid.Column="1" Text="{Binding Title}" Style="{StaticResource PageHeaderTextStyle}">
<TextBlock.Transitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</TextBlock.Transitions>
</TextBlock>
I just came up against exactly the same issue. The way to solve it is to nest the TextBlock one level away from the Grid with the transition on it, for example with a second Grid.
What happens is the transition applies a transform to each of its children, but any transform they may have had is replaced temporarily until after the animation completes, resulting in the nasty 'snap' when the original transform is applied afterwards.
In the following example, the transition will run, replacing the TextBlock's transform, and then after the transition ends the original transform will be applied. You see the 'snap':
<Grid Style="{StaticResource LayoutRootStyle}">
<TextBlock Text="Header" Style="{StaticResource PageHeaderTextStyle}"
Margin="0,0,0,40"/>
</Grid>
In the next example, the transition runs and the transform is applied to the Grid, leaving the TextBlock's transform unaffected. No 'snap':
<Grid Style="{StaticResource LayoutRootStyle}">
<Grid>
<TextBlock Text="Header" Style="{StaticResource PageHeaderTextStyle}"
Margin="0,0,0,40"/>
</Grid>
</Grid>
Hope this helps!
From your words it just seems like the EntranceThemeTransition animates the transform of your TextBlock. The simplest way around that would be to either put the entrance transition on a parent element, or put the transform on one. You could simply wrap your TextBlock in a Grid to do it.

How display a text using silverlight in Windows phone 7

I need to display a text "welcome" on the right-bottom corner of a canvas with red colour
this is my xaml code
<Canvas x:Name="imageOne" Background="White" Width="480" Height="800" >
</Canvas>
please help me
Canvas defines an area within which you have to explicitly position TextBlock element by coordinates relative to the Canvas area. Means you have to do absolute positioning inside a Canvas.
If you really want to use a Canvas, you can better take a transparent Grid inside it and put a TextBlock inside that Grid.
Example:
<Canvas x:Name="imageOne" Background="White" Width="480" Height="800">
<Grid Width="480" Height="800">
<TextBlock Text="Visifire" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
</Grid>
</Canvas>
Please make sure that the Grid size is same as Canvas size.