Silverlight Border object not visible when theme applied? - silverlight

I have a applied one of the Silverlight Toolkit themes to my XAML page, and now for some reason my Border objects don't show up. Is this by design? I've made sure to explicitly state a BorderBrush color that should contrast the theme background, but this does not fix the issue.
In case it helps, the theme I'm using is the BureauBlack theme from the Silverlight Toolkit.
And here is a code snippet of one of my Borders.
<Border VerticalAlignment="Top" Grid.Column="0" Grid.Row="2" Grid.RowSpan="2" BorderBrush="Orange" CornerRadius="10" Margin="0" Height="300">
<StackPanel>
<TextBlock Text="Status Panel" FontSize="20" TextAlignment="Center" />
...
</StackPanel>
</Border>

It looks like when a theme is loaded it loads its own default set of values for most object properties. In this case, the BorderThickness property of the border object defaults to 0. As a result you don't see it.
By explicitly giving the BorderThickness property a value (non-zero ofcourse), I got my border to show up.

In addition, I can recommend Silverlight Spy tool.
One of the feature of Silverlight Spy is to provide a tree of all controls, to display all their properties and to provide an ability to dynamically change them. It greatly decrease time for such problem resolving.
I've used it several times in cases like your.

Related

Why does WP7 ListPicker have different margins and height to TextBox

I have a page in my WP7 app consisting of a TextBox beside a ListPicker. In their default modes, they don't line up properly; the ListPicker has a different padding to the TextBox, and its height is also different.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Orientation="Horizontal">
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top"/>
<toolkit:ListPicker Width="170" ItemsSource="{Binding l}" Style="{StaticResource ListPickerStyle1}" VerticalAlignment="Top"/>
</StackPanel>
</Grid>
Manually tweaking the ListPicker's template to fit in correctly here is tricky and error prone. For example, when its height is adjusted, the caption (i.e. the text of the selected item) is no longer in the centre of the component.
My app is currently failing MS app review because the components are not all the same height.
Is there an easy way for me to set the toolkit:ListPicker to have the same appearance as a TextBox?
The simplest solution will be to take a copy of the the default style and tweak that using Blend to be exactly how you want it to look. This will take a little trial and error to sort out.
You can then use the implicit styling rules to apply it to all ListPickers without having to explicitly set the style on each instance:
<Style x:Key="MyListPickerStyle
TargetType="toolkit:ListPicker>
.... your tweaks here
</Style>
<Style TargetType="toolkit:ListPicker"
BasedOn="{StaticResource MyListPickerStyle}" />
It may be easier to tweak the TextBox Style of course :)

Silverlight: How do I design a custom layout control?

I want to create a custom control named DetailRegion that accepts a collection of child controls. From there I want layout the controls in a manner of my choosing. For example...
<localControls:DetailRegion>
<TextBlock Text="Occupation:" Style="{StaticResource Label}" />
<TextBlock Text="{Binding Occupation}" Style="{StaticResource Value}" />
</localControls:DetailRegion>
... may be rendered as a grid with two columns or a stack panel depending on screen width.
I'm not asking for a complete solution, I just need tutorial to get me started.
Msdn have also good sample, where custom panel creation is described.

Infobox in WPF Bing Maps

I've recently started doing some stuff in WPF and I came up with an idea to integrate maps into my application. I tried some stuff with Google Maps, but the capabilities aren't that great, so after a while I gave up on Google Maps in WPF.
A little while later I bumped into Bing Maps. This looked way more promising than Google Maps to use with WPF. I've started playing around with Bing's Maps and the capabilities are great!
However, when I tried to put a pushpin on the map it wasn't immediately clear to me how to add a infobox to the pushpin, when hovering over it. I have found some examples how to do so, but it required procedural code linked to the xaml. I was actually looking for a method without using procedural code.
Is it possible to add a infobox to a pushpin with just xaml? Or does anyone have a good alternative method on how to do so?
There is a tooltip property available though, but I wasn't actually looking for that. I was actually looking for Google Maps' pushpin kind of style (if it is available).
Assuming I understand correctly what you want, I believe the short answer is: Sorry, but it's not possible to add a Google-Maps-style info box to a pushpin with just XAML. However, I'll try to help if I can.
Disclaimer: I've been playing with the Bing Maps control for Silverlight, so hopefully this will be applicable to the WPF version of the control as well.
I imagine that you don't want to use the built-in ToolTip either because you want it to look different (i.e. not just a yellow box with text) or because you want it to not disappear when the user moves the mouse away.
If you just want it to look different, I can offer the following. When I specified a template for my Pushpins, I went ahead and used a re-templated ToolTip and allowed the user to click the pushpin to get more information.
Here's the ToolTip template, defined as a StaticResource, which of course could contain anything you want:
<Style x:Key="MyToolTipStyle" TargetType="ToolTip">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border CornerRadius="5" BorderBrush="Black" BorderThickness="2" Background="#5c87b2">
<ContentPresenter Margin="5">
<ContentPresenter.Content>
<StackPanel Margin="5" MaxWidth="400">
<TextBlock Text="{Binding Name}" FontWeight="Bold" FontSize="16" Foreground="White" TextWrapping="Wrap"/>
<TextBlock Text="{Binding Description}" Foreground="White" TextWrapping="Wrap"/>
</StackPanel>
</ContentPresenter.Content>
</ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And here's where I used it:
<maps:Map>
<maps:MapItemsControl ItemsSource="{Binding SearchResultsManager.Items}">
<maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<maps:Pushpin Location="{Binding Location}" Cursor="Hand" MouseLeftButtonUp="Pushpin_MouseLeftButtonUp">
<ToolTipService.ToolTip>
<ToolTip Style="{StaticResource MyToolTipStyle}" />
</ToolTipService.ToolTip>
</maps:Pushpin>
</DataTemplate>
</maps:MapItemsControl.ItemTemplate>
</maps:MapItemsControl>
</maps:Map>
Then I'd handle when the user clicked on the pushpin to take them to a details area.
private void Pushpin_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
// Get a reference to the object that was clicked.
var clickedSearchResult = (sender as FrameworkElement).DataContext as SearchResultViewModel;
// Do something with it.
}
However, I imagine you want to keep the ToolTip from disappearing, so that the user can click on controls inside it. Unfortunately, I'm not sure there's a simple way to do that. You might have to define your own custom control, which of course would require some C#/VB code.
Perhaps this new control could derive from Pushpin, and it could show the info box content on mouse-over and/or click. You could use the VisualStateManager to keep most of the code in XAML. The C#/VB would just have to provide a dependency property for the content and some overrides to transition between the visual states at the correct times.
I hope that's at least a little bit helpful!

Silverlight: TextBox VerticalContentAlignment="Center"

I'm trying to vertically center the content of a TextBox with the VerticalContentAlignment property but it seems to have no effect at all. The text stays at the top. Can anyone tell me how to do this?
Here's my code:
<TextBox Grid.Column="1"
Grid.Row="0"
Width="200"
Height="28"
VerticalAlignment="Center"
VerticalContentAlignment="Center" />
It is possible to make the TextBox center its text vertically. However, that does require you to reapply its ControlTemplate.
To do this:
Copy the Style and the ControlTemplate from the TextBox Styles and Templates page on MSDN to a suitable <UserControl.Resources> element. (This ControlTemplate is actually for a validation tooltip; the ControlTemplate we'll change is within the Style.)
Find the ScrollViewer element within the Style for the TextBox, and add a VerticalAlignment="Center" property to it.
Alternatively, you could add the property
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
to the ScrollViewer. This should allow you to set the vertical alignment of the contents of your TextBoxes using the VerticalContentAlignment property.
You can follow much the same approach if you wish to change the horizontal alignment of a TextBox's content as well.
The XAML code is correct, the following should be sufficient:
<TextBlock Text="Centered Text" VerticalAlignment="Center" />
Can you try that code outside your grid?
Check the attributes you defined on your Grid, this will probably cause the behaviour you have. Can you post the complete XAML code?

Silverlight toolkit theme not applied to label

Do I have to do something special to the Label control from the Silverlight toolkit to get the current themed applied?
When looking at the Theme Browser on the demo page it appears as though labels should be turning white in the expression dark theme, but it's staying black for me.
it works fine for me. You might have an implicit or explicit Label style that overwrites it.
Edit:
<Grid x:Name="LayoutRoot">
<toolkit:ExpressionDarkTheme>
<Grid>
<sdk:Label Content="label" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</toolkit:ExpressionDarkTheme>
</Grid>

Resources