WP7 Mango: Retemplating PhoneApplicationFrame created "Unspecified Error" exception - xaml

The following used to work in WP 7.0:
I'm attempting to re-template the root PhoneApplicationFrame in my Mango beta 2 refresh (7712) project with the following Xaml:
<Style TargetType="phone:PhoneApplicationFrame" x:Key="FrameStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border x:Name="ClientArea" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" >
<Grid>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
<toolkit:PerformanceProgressBar IsIndeterminate="True" VerticalAlignment="Top" Margin="0,8,0,0" Visibility="{Binding Path=GlobalProgressVisibility, Source={StaticResource RootFrameViewModel}}" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
When the application launches I get an App.UnhandledException with the text "Unspecified error" and no stack trace. Has anyone seen this?

Blend was helpful in pointing out some properties that shouldn't be set in Mango. Removing the Content and ContentTemplate properties fixed the issue.

I can't reproduce exactly your problem, but I had the same error retemplating a listbox.
Try setting the TargetType property on the ControlTemplate (worked for me) :
<ControlTemplate TargetType="phone:PhoneApplicationFrame">

Related

Customize GroupItem HeaderTemplate UWP

I'm doing an UWP project and I wan't to customize the HeaderTemplate of the group items, but I m unable to find how to fully customize it.
<ListView ItemsSource="{x:Bind ContactsCVS.View}"
ItemTemplate="{StaticResource ContactListViewTemplate}"
SelectionMode="Single"
ShowsScrollingPlaceholders="True"
Grid.Row="1"
Grid.ColumnSpan="2">
<ListView.GroupStyle>
<GroupStyle >
<GroupStyle.HeaderTemplate>
<DataTemplate x:DataType="data:GroupInfoList">
<TextBlock Text="{x:Bind Key}"
Style="{ThemeResource itleTextBlockStyle}"/>
<!-- Can't fully customize this part ?-->
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
I m basing my test on this official example :
https://github.com/Microsoft/Windows-universal-samples/blob/de1bb527ec0327b767397d4c1a74a797356f4357/Samples/XamlListView/cs/Samples/SimpleListViewSample/SimpleListViewSample.xaml
I try to replace the letters A, B, C... With a blue strip and custom text. Looks very simple but can't figure out how it works.
Thanks
The HeaderTemplate defines the template of the header content, but the actual control that displays this content is a ListViewHeaderItem. You can actually simply do this if you want:
<GroupStyle.HeaderTemplate>
<DataTemplate x:DataType="data:GroupInfoList">
<Border Background="LightSkyBlue">
<TextBlock Text="My custom text" />
</Border>
</DataTemplate>
</GroupStyle.HeaderTemplate>
When the ListView is rendered, the ListViewHeaderItem for each group will show the above content, but the control itself still has its own default style.
If you want to style the control as well, to maybe make it stretch horizontally or something, you'll have to create your own style for HeaderContainerStyle:
<GroupStyle.HeaderContainerStyle>
<Style TargetType="ListViewHeaderItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewHeaderItem">
<ContentPresenter
x:Name="ContentPresenter"
Background="Red"
Margin="0"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="Stretch"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTransitions="{TemplateBinding ContentTransitions}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.HeaderContainerStyle>
The ContentPresenter is responsible for showing the Content of the control, in this case the content is whats inside the HeaderTemplate.

Update color of SelectionIndicator in NavigationView

I'm using the NavigationView control to provide the left pane hamburger menu navigation in my UWP app.
I'd like to change the color of the selection indicator (the little rectangle that shows up next to the item you selected).
In generic.xaml I can see the color is being set to the system accent color:
<Style TargetType="NavigationViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="NavigationViewItem">
<Grid
x:Name="LayoutRoot"
Height="40"
Background="{TemplateBinding Background}"
Control.IsTemplateFocusTarget="True">
<!-- Wrap SelectionIndicator in a grid so that its offset is 0,0 - this enables the offset animation. -->
<Grid
HorizontalAlignment="Left"
VerticalAlignment="Center">
<Rectangle
x:Name="SelectionIndicator"
Width="6"
Height="24"
Fill="{ThemeResource NavigationViewSelectionIndicatorForeground}"
Opacity="0.0"/>
</Grid>
<Border
x:Name="RevealBorder"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<Grid Height="40" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="IconColumn" Width="48" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Viewbox x:Name="IconBox"
Child="{TemplateBinding Icon}"
Margin="16,12"/>
<ContentPresenter x:Name="ContentPresenter"
Grid.Column="1"
ContentTransitions="{TemplateBinding ContentTransitions}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Is there a way in my pages XAML file (that uses the NavigationView) to change the color of the rectangle Fill from NavigationViewSelectionIndicatorForeground to some value I set?
I know I could copy over the entire template and update the copy, and set the template on the NavigationView, but it seems like a lot of overhead just to change one value.
You can just define your own brush with x:Key="NavigationViewSelectionIndicatorForeground" for example in App.xaml:
<Application ...>
<Application.Resources>
<SolidColorBrush x:Key="NavigationViewSelectionIndicatorForeground"
Color="Yellow" />
</Application.Resources>
</Application>
Alternatively you could also declare the resource in the scope of your Page or even in your NavigationView's Resources, it just needs to be in the path in the XAML tree leading to the NavigationView.
Because your resource goes later in the cascade, it will override the default NavigationViewSelectionIndicatorForeground with your defined brush.

Windows phone textbox rounder corners in ControlTemplate, Caret is disappeared

Im using this xaml design for a rounder textbox and it works, the only problem is the caret is disappeared, I tried changing the CaretBrush but still the same problem
Here is the xaml
<TextBox x:Name="db" Margin="10" Height="54"
CaretBrush="Red"
BorderBrush="Gray" >
<TextBox.Template>
<ControlTemplate TargetType="TextBox">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="10">
<ContentPresenter Content="{TemplateBinding Text}"
Margin="10,5,5,5"
/>
</Border>
</ControlTemplate>
</TextBox.Template>
</TextBox>

SilverLight 5 toolkit

I'm working an application that is based on Silverlight 5. It's framework 4.5 is MVVM architecture and implemented by Prism. I'm using silverlight 5 toolkit too.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"
xmlns:controlsPrimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
xmlns:telerikTabControl="clr-namespace:Telerik.Windows.Controls.TabControl;assembly=Telerik.Windows.Controls.Navigation"
xmlns:telerikNavigationPrimitives="clr-namespace:Telerik.Windows.Controls.Primitives;assembly=Telerik.Windows.Controls.Navigation"
xmlns:local="clr-namespace:UFone_CRM_UI.Themes"
xmlns:dataPrimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:Telerik_Windows_Controls_GridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView">
<ControlTemplate TargetType="controls:Calendar">
<StackPanel x:Name="Root" HorizontalAlignment="Center" VerticalAlignment="Top">
<controlsPrimitives:CalendarItem x:Name="CalendarItem" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Foreground="{TemplateBinding Foreground}" Style="{StaticResource System.Windows.Controls.Primitives.CalendarItem}" IsEnabled="True" />
</StackPanel>
</ControlTemplate>
<controlsPrimitives:DatePickerTextBox x:Name="TextBox" Margin="0,0,20,0" Height="22" Background="{TemplateBinding Background}" SelectionBackground="{TemplateBinding SelectionBackground}" BorderThickness="1,1,0,1" Foreground="{TemplateBinding Foreground}" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" Padding="{TemplateBinding Padding}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Style="{StaticResource System.Windows.Controls.Primitives.DatePickerTextBox}"/>
This sample buid successed but at runtime in InitializeComponent() method I got this Error =>
The type 'controlsPrimitives:CalendarItem' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built
The type 'controlsPrimitives:DatePickerTextBox' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built
If I delete controls, CalenderItem or DatePickerTextBox the Error do not occur.
How can I solve this problem.
Have you added a reference to System.Windows.Controls?

XAML: accessing nested control property

Can I access the 'Background' property of a grid that lies inside this control, so that I could override the default image where it is required.
<LocalControls:HeaderedContentControl
Style="{StaticResource MultilineHyperlinkStyle}"
Header="autocompletebox"
Content="Completion of text based on items"
/>
The default image is defined here in this Style.
<Style TargetType="LocalControls:HeaderedContentControl">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="LocalControls:HeaderedContentControl">
<Grid>
<Grid.Background>
<!-- ::: DEFAULT IMAGE ::: -->
<ImageBrush ImageSource="/eSurveyWin7;component/Images/50x50.png" />
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="50"/>
<ColumnDefinition Width="Auto" MinWidth="173"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ContentPresenter
Grid.Column="1"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Cursor="{TemplateBinding Cursor}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
<ContentPresenter
Grid.Column="1"
Grid.Row="1"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Cursor="{TemplateBinding Cursor}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I only want to modify the first snippet.