I have a hubtile in my application which opens contacts for dialling a number. Now, i wanted to pin that into the start page of windows and i am implementing this feature by using the below code:
private void Click_Tap(object sender, RoutedEventArgs e)
{
ShellTile oTile = ShellTile.ActiveTiles.FirstOrDefault(x =>
x.NavigationUri.ToString().Contains("flip".ToString()));
if (oTile != null && oTile.NavigationUri.ToString().Contains("flip"))
{
FlipTileData oFliptile = new FlipTileData();
oFliptile.Title = "Hello WP8!!";
oFliptile.Count = 11;
oFliptile.BackTitle = "Updated Flip Tile";
oFliptile.BackContent = "back of tile";
oFliptile.WideBackContent = "back of the wide tile";
oFliptile.SmallBackgroundImage = new Uri("Assets/Tiles/Flip/h.jpg", UriKind.Relative);
oFliptile.BackgroundImage = new Uri("Assets/Tiles/Flip/h.jpg", UriKind.Relative);
oFliptile.WideBackgroundImage = new Uri("Assets/Tiles/Flip/h.jpg", UriKind.Relative);
oFliptile.BackBackgroundImage = new Uri("/Assets/Tiles/Flip/h.jpg", UriKind.Relative);
oFliptile.WideBackBackgroundImage = new Uri("/Assets/Tiles/Flip/h.jpg", UriKind.Relative);
oTile.Update(oFliptile);
MessageBox.Show("Flip Tile Data successfully update.");
}
else
{
Uri tileUri = new Uri("/phoneNumberChooserTask.show()?tile=flip", UriKind.Relative);
ShellTileData tileData = this.CreateFlipTileData();
ShellTile.Create(tileUri, tileData, true);
}
}
private ShellTileData CreateFlipTileData()
return new FlipTileData()
{
Title = "",
BackTitle = "",
BackContent = "",
WideBackContent = "",
Count = 8,
SmallBackgroundImage = new Uri("/Assets/Tiles/Flip/h.jpg", UriKind.Relative),
BackgroundImage = new Uri("/Assets/Tiles/Flip/h.jpg", UriKind.Relative),
WideBackgroundImage = new Uri("/Assets/Tiles/Flip/h.jpg", UriKind.Relative),
};
}
The problem i am facing is when i run this on a device/emulator, Tile gets pin to start but when i click the tile on the start screen of my device/emulator debugger stops the process and the process breaks.
Can anyone guide me in the right direction ?
Tile can not launch anything except your app. Add into uri some code that will be parsed by your app and then your app should call phoneNumberChooserTask.show(). For example:
new Uri("/Chooser.xaml?tile=flip", UriKind.Relative);
Then, in the Chooser.xaml (page in your project), in the OnNavigatedTo detect the title value in the Uri and call phoneNumberChooserTask.show().
Related
Hey all I am not sure why I am having such a hard time with this but I am needing to be able to change a tiles isEnabled property depending on if my program detects an internet connection or not.
The WPF code that I am using and needing to change is the following:
<dxlc:TileLayoutControl x:Name="tileLayoutControl1" Margin="150,63,153,57" Padding="5"
AllowAddFlowBreaksDuringItemMoving="False" AllowItemMoving="False" Orientation="Horizontal" ScrollBars="None"
TileClick="tileLayoutControl1_TileClick">
</dxlc:TileLayoutControl>
This gets populated by the code behind on startup:
private void createMenu()
{
List<String> menuIcons = new List<string>();
menuIcons.Add("gamesIcon.png");
menuIcons.Add("movieIcon.png");
menuIcons.Add("musicIcon.png");
menuIcons.Add("televisionIcon.png");
menuIcons.Add("youTubeIcon.png");
menuIcons.Add("androidIcon.png");
foreach (String item in menuIcons)
{
Image finalImage = new Image();
BitmapImage image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri("/img/" + item.ToString(), UriKind.Relative);
image.EndInit();
finalImage.Source = image;
image = null;
tileLayoutControl1.Children.Add(new Tile()
{
Content = finalImage,
Name = item.ToString().Replace(".png", ""),
Tag = item.ToString().Replace(".png", "").Replace(".jpg", ""),
Width = 255,
Height = 288,
IsEnabled = false,
Margin = new Thickness(0, 0, 50, 20),
Background = Brushes.Transparent,
BorderThickness = new Thickness(0, 0, 0, 0)
}
}
}
and finally the code that I have checking the internet connection within a timer:
private bool checkInternet()
{
try
{
Ping myPing = new Ping();
PingReply reply = myPing.Send("google.com", 1000, new byte[32], new PingOptions());
return (reply.Status == IPStatus.Success);
}
catch (Exception)
{
return false;
}
}
public firstWindow()
{
InitializeComponent();
var startTimeSpan = TimeSpan.Zero;
var periodTimeSpan = TimeSpan.FromMinutes(5);
var timer = new System.Threading.Timer((e) =>
{
bool hasInternet = checkInternet();
TileLayoutControl test = (TileLayoutControl)this.tileLayoutControl1.FindName("youTubeIcon");
test.IsEnabled = true;
tileLayoutControl1.RegisterName("youTubeIcon", this.isEnabled = true);
}, null, startTimeSpan, periodTimeSpan);
}
I am currently not getting any errors for the lines:
TileLayoutControl test = (TileLayoutControl)this.tileLayoutControl1.FindName("youTubeIcon");
test.IsEnabled = true;
tileLayoutControl1.RegisterName("youTubeIcon", this.isEnabled = true);
But test is null and RegisterName doesn't seem to change the isEnabled property when I try to click on the tile.
I've also read that using Command="{Binding ClickCommand}" may be my answer but that seems to only pertain to MVVM type of patterns which I am not using for this particle program.
I also know that checking the tileLayoutCibtril1 has a Children property that does contain my dynamically created icons but tileLayoutCibtril1.Children does not have a .FindName proeprty.
So what am I missing?
Try to call ApplyTemplate on TileLayoutControl after foreach statement. The template for TileLayoutControl has not yet been applied and therefore FindName returns null. ApplyTemplate builds the current template’s visual tree
foreach (String item in menuIcons)
{
...
}
tileLayoutControl1.ApplyTemplate();
I have the following problem. When I start the application, my content does not appear, and only the banner of Google Ad Mob appears.
Only the GPS permission message appears but not the content itself.
The code I use :
public MainPage()
{
InitializeComponent();
_restServiceForecast = new RestServiceForecast();
_ = DisplayHourlyForecastStartUp();
_ = ButtonClickedGPS();
co2lbl.Text = "CO2";
nolbl.Text = "NO";
no2lbl.Text = "NO2";
o3lbl.Text = "O3";
so2lbl.Text = "SO2";
pm2_5lbl.Text = "PM2_5";
pm10lbl.Text = "PM10";
nh3lbl.Text = "NH3";
frameFinePowders.IsVisible = false;
AdmobControl admobControl = new AdmobControl()
{
AdUnitId = AppConstants.BannerId
};
Label adLabel = new Label() { Text = "Ads will be displayed here!" };
Content = new StackLayout()
{
Children = { adLabel, admobControl }
};
this.Title = "Admob Page";
}
How do I make the banner appear under a certain frame that I want?
I am trying to capture the screen in IOS, Other than WkWebview all other view component I am able to capture by below code.WkWebview is giving a blank page as captured data. If I am using UIWebview the same code working Is there anything specific to do to take screen shot WkWebView.
Code for screen capture.
public static UIImage SnapshotView(this UIView view)
{
UIGraphics.BeginImageContextWithOptions(view.Bounds.Size, false, UIScreen.MainScreen.Scale);
view.DrawViewHierarchy(view.Bounds, true);
var image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return image;
}
WkWebView Configuration:
WKWebView _wkWebView = new WKWebView(ReaderView.Frame, new WKWebViewConfiguration());
_wkWebView.LoadFileUrl(tempUrl, tempUrl);
_wkWebView.ContentMode = UIViewContentMode.ScaleToFill;
_wkWebView.BackgroundColor = UIColor.Clear;
_wkWebView.Opaque = false;
_wkWebView.ScrollView.BackgroundColor = UIColor.Clear;
//_wkWebView.DrawViewHierarchy(_wkWebView.Bounds, true);
ReaderView.AddSubview(_wkWebView);
var imag = _wkWebView.SnapshotView();
I fixed the issue by replacing the WKWebView with PdfView.I am using this view for loading PDFs.
The latest code is below
pdfView = new PdfView();
pdfView.TranslatesAutoresizingMaskIntoConstraints = false;
ReaderView.AddSubview(pdfView);
pdfView.LeadingAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.LeadingAnchor).Active = true;
pdfView.TrailingAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TrailingAnchor).Active = true;
pdfView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor).Active = true;
pdfView.BottomAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.BottomAnchor).Active = true;
// var path = Bundle.main.url(forResource: "test", withExtension: "pdf") else { return }
PdfDocument document;
// PdfDocument
using (urlString = new NSString(FilePath))
using (var tempUrl = NSUrl.CreateFileUrl(new string[] { urlString }))
document = new PdfDocument(tempUrl);
//if var document = PdfDocument(url: path) {
pdfView.Document = document;
Firstly I would like to disclose that I am a new developer and just starting out coding with Xamarin and C sharp.
Ok. So I am creating a custom renderer for the map pin in my application. I have been using the following sample code found here: https://github.com/xamarin/xamarin-forms-samples/tree/master/CustomRenderers/Map/Pin
As it currently stands I am trying to set the popup on the pins so that when I click on them they will either go to a page in the app or possibly have a popup come up with more details on that specific pin location. Currently when I click on the pin popup it takes me to a website.
Here is a screen shot of the app:
enter image description here
I have been looking at this code and Im trying to figure out if it would be possible to change the URL to a local page?
InitializeComponent();
var position1 = new Position(52.649005, -7.250712);
var position2 = new Position(52.648061, -7.252879);
var position3 = new Position(52.650519, -7.249260);
var position4 = new Position(52.652680, -7.244724);
var position5 = new Position(52.648061, -7.252879);
var position6 = new Position(52.648061, -7.252879);
var pin1 = new CustomPin
{
Type = PinType.Place,
Position = position1,
Label = "Butler House",
Address = "394 Pacific Ave, San Francisco CA",
Id = "test",
Url = "http://xamarin.com/about/"
};
var pin2 = new CustomPin
{
Type = PinType.Place,
Position = position2,
Label = "Talbots Tower",
Address = "394 Pacific Ave, San Francisco CA",
Id = "",
Url = "http://xamarin.com/about/"
};
In the CustomMapRender.cs file here is where I believe I need to be able to alter the CustomPin.URL to allow me to click and get local pages in the app itself.
protected override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
{
MKAnnotationView annotationView = null;
if (annotation is MKUserLocation)
return null;
var customPin = GetCustomPin(annotation as MKPointAnnotation);
if (customPin == null)
{
throw new Exception("Custom pin not found");
}
annotationView = mapView.DequeueReusableAnnotation(customPin.Id.ToString());
if (annotationView == null)
{
annotationView = new CustomMKAnnotationView(annotation, customPin.Id.ToString());
annotationView.Image = UIImage.FromFile("pin-red-10.png"); //pin is set by image not changable by colour attributes
annotationView.CalloutOffset = new CGPoint(0, 0);
annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("Ireland-icon.png"));
annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);
((CustomMKAnnotationView)annotationView).Id = customPin.Id.ToString();
((CustomMKAnnotationView)annotationView).Url = customPin.Url;
}
annotationView.CanShowCallout = true;
return annotationView;
Any help or insight on this would be much appreciated as Im going around in circles trying so many different things at present.
Thanks
Michael
GetViewForAnnotation method is for getting the MKAnnotationView (i.e., the callout that's displaying the details of the Pin).
What you need is the tap event of the MKMapView callout. Add an EventHandler to CalloutAccessoryControlTapped and handle the logic for navigation.
In the sample provided it would be this part
void OnCalloutAccessoryControlTapped(object sender, MKMapViewAccessoryTappedEventArgs e)
{
// handle navigation here instead of opening the webpage
var customView = e.View as CustomMKAnnotationView;
if (!string.IsNullOrWhiteSpace(customView.Url))
{
UIApplication.SharedApplication.OpenUrl(new Foundation.NSUrl(customView.Url));
}
}
I used this below code to pin the tile, and here i used TileNotificationsPack.dll for updating tile.
Uri Squarelogo = new Uri(ms-appx:///TileImages/150x150.jpg, UriKind.RelativeOrAbsolute);
Uri Widelogo = new Uri(ms-appx:///TileImages/310x150.jpg, UriKind.RelativeOrAbsolute);
Uri smalllogo = new Uri(ms-appx::///TileImages/30x30.jpg, UriKind.RelativeOrAbsolute);
SecondaryTile secondaryTile = new SecondaryTile(ShowId, title, ProjectName, tileActivationArguments, TileOptions.ShowNameOnLogo, Widelogo);
secondaryTile.ForegroundText = ForegroundText.Light;
secondaryTile.WideLogo = Widelogo;
secondaryTile.Logo = Squarelogo;
secondaryTile.SmallLogo = smalllogo;
await secondaryTile.RequestCreateAsync();
Tile image showing in debug mode only when i put app in store tile images are not showing..
I used this below code, and last time i used 250x250 size image for both 150x150.jpg and 30x30.jpg, now i used exact size for images now the tile is working when app is in store..
Uri Squarelogo = new Uri(ms-appx:///TileImages/150x150.jpg, UriKind.RelativeOrAbsolute);
Uri smalllogo = new Uri(ms-appx::///TileImages/30x30.jpg, UriKind.RelativeOrAbsolute);
var tileActivationArguments = "MySecondaryTile Was Pinned At " + DateTime.Now.ToLocalTime().ToString();
SecondaryTile secondaryTile = new SecondaryTile(ShowId, title, tileActivationArguments, Squarelogo, TileSize.Square150x150);
secondaryTile.VisualElements.ForegroundText = ForegroundText.Light;
secondaryTile.VisualElements.Wide310x150Logo = Squarelogo;
secondaryTile.VisualElements.Square30x30Logo = smalllogo;
secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;
secondaryTile.VisualElements.ShowNameOnWide310x150Logo = true;
await secondaryTile.RequestCreateAsync();