I added the TiltEffect.IsTiltEnabled property to my HubTile:
<toolkit:HubTile toolkit:TiltEffect.IsTiltEnabled="True" Title="title" Message="This is message" x:Name="name" DisplayNotification="False" Source="pB.png" Tap="tap" />
I also added the HubTile type to the TiltableItems collection in the page's constructor, per the :
public HubPage()
{
TiltEffect.TiltableItems.Add(typeof(HubtTile));
}
but the HubTile don't have tilt effect....
Thanks!
Try adding your HubTile as Content of HyperLinkButton or Button which supports TiltEffect
Add a Style to PhoneApplicationPage.Resources which works for Button and HyperLinkButton that adds support for other controls as Content
<phone:PhoneApplicationPage.Resources>
<Style x:Key="EmptyButtonStyle" TargetType="primitives:ButtonBase">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Padding" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="primitives:ButtonBase">
<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
Also add the primitives namespace to the page
xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows"
Then use your HubTile as HyperLinkButtons's (or Button) Content like this
<HyperlinkButton Style="{StaticResource EmptyButtonStyle}">
<toolkit:HubTile toolkit:TiltEffect.IsTiltEnabled="True" Title="title" Message="This is message" x:Name="name" DisplayNotification="False" Source="pB.png" Tap="tap" />
</HyperlinkButton>
This will finally support TiltEffect and HubTile
Get TiltEffect from Updated Tilt Effect - Peter Torr's Blog
OR download the Silverlight Toolkit Source from Silverlight Toolkit - Downloads
and then add the HubTile class to the list of 'tiltableItems' in TiltEffect.cs:
/// <summary>
/// Default list of items that are tiltable
/// </summary>
static List<Type> tiltableItems = new List<Type>() { typeof(ListBoxItem) , typeof(HyperlinkButton) , typeof(HubTile) };
If you decide to modify the Toolkit, be sure to build the project on Release, and target the .dll you create inside your own application.
I've found other simple solution that works great when HubTile is used as ListBox.ItemTemplate.
Simply set TiltEffect.IsTiltEnabled="True" on ListBox and IsHitTestVisible="False" on HubTile and voila - it works :) You can still respond to HubTile clicks through ListBox.SelectionChanged event and HubTile has working tilt effect.
Hubtile by default is not added to TiltableItems List and needs to be added manullay...
Add the following code to codebehind
public MainPage()
{
InitializeComponent();
TiltEffect.TiltableItems.Add(typeof(HubTile));
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
and add the following line to your hubtile or grid containing the hub tile
<phone:PanoramaItem CacheMode="{x:Null}" Header="item3" toolkit:TiltEffect.IsTiltEnabled="True">
Related
I just had a very weird issue in my app.
I was adding Syncfusion's SfListView to some pages in my app and for some reason, if the first thing I do when a page that uses the SfListView loads is scroll the ListView, I get a NullReferenceException...in the UIApplication.Main() function that gets called in the iOS project's Main class. There's nothing special in that class at all, though.
It gets better. If I do something else first, like dragging and dropping the items in the SfListView to reorder them and then I scroll it, it doesn't throw the exception.
What on Earth could be causing this?
Here is the XAML for one of the pages that uses the SfListView:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms"
mc:Ignorable="d"
x:Class="Partylist.Views.EventsPage"
Title="Events"
BackgroundColor="White">
<ContentPage.ToolbarItems>
<ToolbarItem IconImageSource="settings_gear.png"
Priority="0"/>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<!--Main layout of the page-->
<StackLayout>
<!--ListView of the events-->
<syncfusion:SfListView x:Name="EventsListView"
SelectionMode="Single"
SelectionGesture="Tap"
SelectionChanged="OnItemSelected"
DragStartMode="OnHold">
<syncfusion:SfListView.DragDropController>
<syncfusion:DragDropController UpdateSource="True"/>
</syncfusion:SfListView.DragDropController>
<syncfusion:SfListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<SwipeView>
<!--Swipe from the right to make some options
appear-->
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem Invoked="OnDelete"
CommandParameter="{Binding .}"
Text="Delete"
BackgroundColor="#ff418b"
IsDestructive="true"/>
<SwipeItem Invoked="OnRename"
CommandParameter="{Binding .}"
Text="Rename"
BackgroundColor="#FF7700"/>
</SwipeItems>
</SwipeView.RightItems>
<!--This is the content that actually appears-->
<StackLayout Padding="20,5">
<Label Text="{Binding EventFolder.Name}"
TextColor="#FF7700"
FontSize="Large"/>
</StackLayout>
</SwipeView>
</ViewCell>
</DataTemplate>
</syncfusion:SfListView.ItemTemplate>
</syncfusion:SfListView>
<!--"New Event" button-->
<Button Text="+ Add New Event"
TextColor="#ff418b"
FontSize="Large"
BackgroundColor="#00ffffff"
Clicked="OnNewEventClicked"/>
<!--The banner at the bottom of the screen that gives tips-->
<Frame BorderColor="#ff418b"
Padding="0"
HeightRequest="75">
<FlexLayout Direction="Row"
AlignItems="Stretch"
JustifyContent="SpaceBetween">
<!--The "Tip" icon-->
<Image Source="tip_icon.png"
Margin="10"
FlexLayout.Basis="50"/>
<!--The short version of the tip-->
<Label x:Name="tipLabel"
VerticalTextAlignment="Center"
TextColor="#bb0099"
FontSize="Medium"
FontAttributes="Bold"
FlexLayout.Basis="240"/>
<!--The button that opens up a screen
with the rest of the tip-->
<Button Clicked="OnMoreClicked"
Text="More"
TextColor="White"
FontAttributes="Bold"
FontSize="Medium"
BackgroundColor="#ff418b"
FlexLayout.Basis="100"/>
</FlexLayout>
</Frame>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Here is the iOS project's Main class:
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace Partylist.iOS
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate"); // This is the line that throws the exception.
}
}
}
UPDATE: I just applied the SfListView to a couple more pages in my project and I couldn't type into the entries in the items on those pages' lists or use their SwipeViews (the experimental ones in Xamarin, not the ones from the SfListView) without crashing the app in the same way as above.
I just got rid of the Synfcusion ListView and switched back to the one that Xamarin comes with. #BenReierson said it's a problems with Xamarin, so maybe I'll look into switching back when that bug gets fixed.
Glad to inform that the reported issue “NullReferenceException throws when scrolling the SfListView with DragDropController” has been included in Syncfusion's latest Weekly NuGet release update version 18.2.0.46 which is available for download (https://www.nuget.org/).
I'm using a custom font in our app, and have found that if I set a FontAttributes="Bold" for a Label style using the font, it works on the iOS simulator, but not on a real device.
Steps taken:
1. Added the font Effra_Std_Reg.ttf to the resources folder.
2. Added this to the Fonts Provided By The Application element in Info.plist and set its build actions.
3. Created Styles in App.XAML.
4. Added these styles to the XAML on my page.
All the above works fine for a Label with no FontAttributes set. As soon as I set FontAttributes="Bold" on either the Style or the Label itself, the system font is used insted. Note that this works on the Simulator.
I know that the FontFamily is the font Name as defined inside the ttf file - not the ttf filename.
This on an iPad running iOS 10.3.3.
My App.XAML is:
<?xml version="1.0" encoding="utf-8" ?>
<Application x:Class="FontTest.App"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<Application.Resources>
<ResourceDictionary>
<Style TargetType="Label">
<Setter Property="FontSize" Value="30" />
</Style>
<Style x:Key="PlainLabelStyle" TargetType="Label">
<Setter Property="FontFamily">
<Setter.Value>
<OnPlatform x:TypeArguments="x:String"
Android="Effra_Std_Rg.ttf#Effra"
iOS="Effra" />
</Setter.Value>
</Setter>
</Style>
<Style x:Key="BoldLabelStyle" TargetType="Label">
<Setter Property="FontFamily">
<Setter.Value>
<OnPlatform x:TypeArguments="x:String"
Android="Effra_Std_Bd.ttf#Effra"
iOS="Effra" />
</Setter.Value>
</Setter>
<Setter Property="FontAttributes" Value="Bold" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
And my page XAML (extract) is:
<Label Grid.Row="4"
Grid.Column="1"
Style="{StaticResource BoldLabelStyle}"
Text="QWERTYUIOPASDFGHJKLZXCVBNM" />
To get it working on the device, I had to include the bold font file (Effra_Std_Bd.ttf), and specify a FontFamily of 'Effra-Bold'.
So it appears that the FontFamily needs to be the Name and the Style.
Strange that it worked on the Simulator.
I started to use advertising control, but I'm going crazy trying to let it work.
I copied PivotPage.xaml from Microsoft Ad Control Sample and made it the starting page in my app, but ad control is not shown (I'm not able to see banner); if I try to run Microsoft app, banner is shown.
So I registered my app on pubCenter and I got an appId and a unitId and tried to use them in my app, but the result is the same: no banner!!
If I try to use my ids in Microsoft app, test banner is shown.
Why using Microsoft example I'm able to see banner and using same page in my app I can't?
Why using my ids, Microsoft app does not show correct banner?
Here is XAML
<!--Pivot Control-->
<controls:Pivot Grid.Row="0" Title="Ad Control Sample">
<!--Pivot item one-->
<controls:PivotItem Header="piv 1">
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Header="piv 2">
</controls:PivotItem>
<!--Pivot item three-->
<controls:PivotItem Header="piv 3">
</controls:PivotItem>
</controls:Pivot>
<StackPanel Grid.Row="1" VerticalAlignment="Bottom" >
<TextBlock Text="This is the same ad."
TextWrapping="Wrap"
HorizontalAlignment="Stretch"
TextAlignment="Center" />
<my:AdControl Name="adControl1"
ApplicationId="test_client"
AdUnitId="Image480_80"
HorizontalAlignment="Center"
Width="480" Height="80" />
</StackPanel>
I finally managed to solve my problem and I want to share solution.
I add an event handler for ErrorOccurred on ad control and reading Microsoft.Advertising.AdErrorEventArgs e I realized that my manifest (WMAppManifest.xml) was missing
<Capability Name="ID_CAP_IDENTITY_USER" />
<Capability Name="ID_CAP_MEDIALIB" />
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
I'm trying style the TimePicker control that appears on the form so that the text colour changes accordingly to the phone's style with a transparent background. For normal text, I just use:
Style="{StaticResource PhoneTextNormalStyle}"
However, this won't work for the TimePicker and I get an error when I try to build the project.
Sorry for the severe lack of detail right now, I current don't have access to my development box right now. When I get home I'll post a screenshot of the control and the error.
The easy way to do this would be in Expression Blend. Open up the project in there, right-click on the control and select "Edit Style" -> "Edit a copy". This will put a style element into the page.resources section that looks like the following snippet
<Style x:Key="TimePickerStyle1" TargetType="toolkit:TimePicker">
<Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="PickerPageUri" Value="/Microsoft.Phone.Controls.Toolkit;component/DateTimePickers/TimePickerPage.xaml"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="toolkit:TimePicker">
<StackPanel>
<ContentControl ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{StaticResource PhoneSubtleBrush}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="12,0,12,-4"/>
<Button x:Name="DateTimeButton" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Content="{TemplateBinding ValueString}" Foreground="{TemplateBinding Foreground}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Height="72"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
and your control definition will look like this:
<toolkit:TimePicker Name="TimePickerInstance" Style="{StaticResource TimePickerStyle1}"></toolkit:TimePicker>
Of course, you can put this snippet in there yourself, and reference it in the same way in the control. It will all work the same way - Expression Blend just makes the process of doing it much simpler.
You should be able to manipulate that as you need to from there, probably changing the 2nd and 4th lines to
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}"/>
Hope that helps.
My ViewModel has a property called Commands which is of type IDictionary.
For my data grid I have created a ControlTemplate for one of the fields using a button as follows:
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Button Style="{DynamicResource btnRemove}" Width="14" Height="14"
Content="{TemplateBinding Content} "
CommandParameter="{Binding ViewID}"
Command="{Binding Commands[AcknowledgeErrorCmd]}" />
<ControlTemplate.Triggers>
</ControlTemplate.Triggers>
</ControlTemplate>
Clicking on the button does nothing which tells me the binding did not work. However, an unstyled button added to the toolbar of the same window hosting this grid works, binds properly to this command. I guess my question is:
Hw do I bind the command property of a button used in a ControlTemplate to a ViewModel?
TIA.
I am not sure what the problem is but try to debug your solution and look into the output window with Debug selected in the combobox and you will see the errors that occur during binding. Maybe this will help you to the solution.
Provide me the error as a comment on this post if you don't understand it.
I did this instead:
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Border >
<TextBlock Margin="5">
<Hyperlink
CommandParameter="{Binding ElementName=root, Path=DataContext.ViewID}"
Command="{Binding ElementName=root, Path=DataContext.Commands[AcknowledgeErrorCmd]}">
<TextBlock Text="Acknowledge"/>
</Hyperlink>
</TextBlock>
</Border>
</ControlTemplate>
and that works fine. It may be related to the post Viko provided.