show a label always at the bottom of the page in silverlight - silverlight

In my Silverlight Application , I have a label which contains the copyright information.I want to show the label always at the bottom of the screen in every resolution.
<sdk:Label
Height="28"
x:Name="label1"
Width="422"
Content="Copyright © 2013. All rights reserved." Margin="253,662,252,-41" />
with margin I am only able to show it at bottom on my screen.
How to do it?

You can use Grid with two Rows. One "Stretch" Height="*" and the second adaptable to content Height="Auto". Use HorizontalAlignment for the label :
<Grid x:Name="LayoutRoot" >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid>
<!-- Main content -->
</Grid>
<!-- Put the label in row 1 : Grid.Row="1"-->
<!-- elastic width :) : HorizontalAlignment="Stretch"-->
<sdk:Label
Grid.Row="1"
Height="28"
x:Name="label1"
HorizontalAlignment="Stretch"
Content="Copyright © 2013. All rights reserved." />
</Grid>

Related

WPF: Two borders with solid background have a ugly pixel row on top (merging color with parent panel's background)

Below there is shown a simple part of my wpf app where you can see two borders (1. and 2.).
At 3. you can see a lite red line (which is my problem). This line was never (explicitly) defined in xaml code. The red background was only defined in a parental grid and is gleam through at the top of the border element. Below Is my code:
<Window
x:Class="BgColorBug.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="200" Width="200"
WindowStartupLocation="CenterScreen"
>
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="1" Background="Red">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Border
Grid.Row="0"
Height="4" Background="#1F1F1F" />
<Border
Grid.Row="1"
Background="#777777"
>
<WrapPanel
Orientation="Horizontal"
HorizontalAlignment="Right"
>
<Button Padding="7" Margin="7">Hello</Button>
<Button Padding="7" Margin="7">World</Button>
</WrapPanel>
</Border>
</Grid>
</Grid>
When I define fix row heights (instead of the auto value) then the red line is not showing so I think it's a rendering problem (by the side the border from 1. has a red line too).
While I has written my question I found that article with the solution to my problem.
There must be declared UseLayoutRounding="True" on any grid above the last one (because that value is inherited down).
<Grid Grid.Row="1" Background="Red" UseLayoutRounding="True">
After known the keyword 'LayoutRounding' I found this Article on StackOverflow with a similar problem.
After knowing the issue with LayoutRounding=False I don't know what are the benefits from not using it? Maybee performance?
What is the best practise using that flag? In some Microsoft articles they say to set it true on the root element (which is the main window). But if so then I'm wondering why that flag is not true by default.

scrollviewer the property 'content' is set more than once

Here my code:
<Grid Style="{StaticResource LayoutRootStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollViewer
Grid.RowSpan="2" Style="{StaticResource HorizontalScrollViewerStyle}"
HorizontalScrollBarVisibility="Visible" >
<!-- The elements you want to be horizontally scrollable goes here -->
<!-- Horizontal scrolling grid used in most view states -->
<GridView
Name="itemGridView"
AutomationProperties.AutomationId="ItemsGridView"
AutomationProperties.Name="Items"
TabIndex="1"
Padding="100,136,116,46"
ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
SelectionMode="None"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
ItemClick="ItemView_ItemClick"/>
<Button Hello /> <!-- From here come the Error -->
</ScrollViewer>
</Grid>
When I add any thing after my GridView, it give me that error (the property content is set more than once).
The answer is right there in the error message. A ScrollViewer can only have one child (you have two, a GridView and a Button). If you want to add multiple things, you will have to wrap them in a panel that allows multiple children (e.g. Grid).

How to bind Font Size to variable Grid Size

I have a grid with 2 columns and 2 rows. A single character (Unicode U+2699) was placed inside the bottom right grid field. It looks like this:
I´d like the character to automatically adjust its font size to fit the grid field it has been placed in (in this case it should be bound to the height of the second grid row, but since in some cases it could be unclear if the height or the width of the grid is smaller, it would be also nice to know how to bind to the lowest of those 2 values).
My implementation so far is something like the following (I simplified it a bit for this example):
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition x:Name="heightToBind" Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="14*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button FontSize="{Binding ElementName=heightToBind, Path=Height.Value, Mode=OneWay}" Content="⚙" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" />
</Grid>
The problem here is, that it only works if the height is a fixed value inside the RowDefinitions. I want it to work with the following definition:
<Grid.RowDefinitions>
<RowDefinition Height="4*"/>
<RowDefinition x:Name="heightToBind" Height="*"/>
</Grid.RowDefinitions>
As a bonus question I´d also be interested why it might be that the character is placed too low so it is getting cut off at the bottom (I tried VerticalAlignment="Center" for the button but with no effect).
You can try using a ViewBox as the button's content:
<Button Grid.Row="1" Grid.Column="1">
<Button.Content>
<Viewbox StretchDirection="Both" HorizontalAlignment="Stretch">
<TextBlock Text="⚙" />
</Viewbox>
</Button.Content>
</Button>
A ViewBox can stretch and scale his child to fill all the available space...
You could try binding to the ActualHeight instead of the Height:
<Button FontSize="{Binding ElementName=heightToBind, Path=ActualHeight.Value, Mode=OneWay}"
Content="⚙" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" />
This should work.
The * on the grid definition means take the available space as the height so it's only determined when the page layout has been prepared for layout. If the height is either unset or changed then the real height is returned in the ActualHeight property.

WPF: Star in ColumnDefinition not expanding columns

I have a user control that need the 1st and 3rd column to have the same width at all time.
My code is a follows:
<UserControl x:Class="UserControls.ListBoxSelector"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="5*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ListBox x:Name="ListBox_Source" Grid.Column="0" Grid.Row="0" />
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Vertical">
<Button Content=">" Click="Button_Add_Click"/>
<Button Content="<" Click="Button_Remove_Click" />
</StackPanel>
<ListBox x:Name="ListBox_Destination" Grid.Column="2" Grid.Row="0" />
</Grid>
</UserControl>
The result is not as expected as column 3 (ListBox_Destination) is not expanded at all.
Isn't the 5* in ColumnDefinition enough to force the 2 listbox to the same width??
UPDATED : Sorry that I forgot to mention that the problem only occurs when I put the control inside a RibbonGroup using Microsoft Ribbon for WPF
Sometimes, when you put your control in certian types of layout controls (like a StackPanel), it won't size as expected because the parent layout will only size the child to it's minimum desired size (just enough to show the content). This may be why you are seeing this when you put it in the RibbonGroup. Try giving your Grid a Width or MinWidth and see if that makes a difference.
yes it forces the columns 1 and 3 to be of the same size, but it doesnt gaurentee the content (listboxes) inside the colulms will be of the same size. You have to set the size of content to take up whole space

WP7/Silverlight: how to disable/remove adctrol from visual tree

I am building a app that supports trial and I want to show ads in trials and no ads in paid. Upon investigation I found that the only way to disable the ads for paid version is to remove the adcontrol completely from the visual tree.
Now my question is how do I remove the adcontrol from my visual tree in my code when I detect it is a paid version and not a trial. Can you please help?
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
...
</Grid>
<Grid Grid.Row="1">
...
</Grid>
<Grid Grid.Row="2">
<ad:AdControlx:Name="itemAds" .../>
</Grid>
</Grid>
If you set the Visibility of the control to Visibility.Collapsed it will be removed from the visual tree.
You therefore just need one line of code:
itemAds.Visibility = Visibility.Collapsed;
You don't even need to name the grid:
var parent = itemAds.Parent as Grid;
if (parent != null)
{
parent.Children.Remove(itemAds);
}
Could you name the Grid that is wrapping the AdControl and then call, myGrid.Children.Clear() ?

Resources