I'am doing localized application in WP7 so I make my app bar in code. The problem appears when I have some form (registration, login etc.). In Blend everything looks all right, but when I emulate it on device my gird with textboxes, textblocks is totally different (sometimes they are on each other)
My solution is to build empty app bar in Blend (PhoneApplicationPage -> New (Common Properties)) and then make new one in code like that:
private void BuildApplicationBar()
{
// Set the page's ApplicationBar to a new instance of ApplicationBar.
ApplicationBar = new ApplicationBar();
// Create a new button and set the text value to the localized string from AppResources.
ApplicationBarIconButton OkAppBarButton = new ApplicationBarIconButton(new Uri("icons/ok.png", UriKind.Relative));
OkAppBarButton.Text = AppResource.OkAppBarButton;
ApplicationBar.Buttons.Add(OkAppBarButton);
OkAppBarButton.Click += new EventHandler(OkAppBarButton_Click);
ApplicationBarIconButton CancelAppBarButton = new ApplicationBarIconButton(new Uri("icons/cancel.png", UriKind.Relative));
CancelAppBarButton.Text = AppResource.CancelAppBarButton;
ApplicationBar.Buttons.Add(CancelAppBarButton);
CancelAppBarButton.Click += new EventHandler(CancelAppBarButton_Click);
}
Works good, but I wanted just to be sure is that the proper way to handle with that?
#dargod. There are a number of frameworks around to help build and bind the appbar. The key problem with the app bar that many people have complained about is that fact that the bar does not support commanding out of the box, so does not lend itself to MVVM.
Here are some links that may help
AppBarUtils
Bindable App bar
Related
Using xamarin forms (PCL),
I searched a lot but Can not find the exact solution,
Can i change the back button in toolbar or at least should i be able to change its color and the title color as well?
I am not sure for changing back button, but I was changing back button and title color.
An example, in App.cs file OnStart method I set that LoginPage is first page with black title, on this way
MainPage = new NavigationPage(new LoginPage()) { BarTextColor = Color.Black };
Please try something like this, I have some other examples if this one doesn't work.
My application is developed using Xamarin.iOS and I need to make it accessible. We couldn't find any help to achieve large text accessibility in xamarin.iOS. I found this link which explains how to achieve it in Xamarin.Forms and this about MonoTouch. Could someone help me how to achieve Large text accessibility on Xamarin.iOS.
Assign one of the UIFontTextStyles to your UI elements and when the app starts the element's text size will be set based upon the UIFontTextStyle and the user's current Accessibility Larger Text setting:
var uiLabel = new UILabel(new CGRect(40, 40, 200, 40));
uiLabel.Text = "StackOverflow";
uiLabel.Font = UIFont.GetPreferredFontForTextStyle(UIFontTextStyle.Body);
View.AddSubview(uiLabel);
If you want to dynamically response to the Accessibility Larger Text changes so the user does not have to restart your app, subscribe to UIContentSizeCategoryDidChangeNotification and update your views:
NSNotificationCenter.DefaultCenter.AddObserver(
new NSString("UIContentSizeCategoryDidChangeNotification"),
(NSNotification obj) =>
{
Console.WriteLine("Update layouts/subviews/layers/etc...");
View.SetNeedsLayout();
},
null
);
MonoTouch and Xamarin.iOS are the same thing, just a different name.
It is achieved in the exact same way, where you set the Font property of your UILabel or UITextField to one of the available fonts in the UIFont static class like so:
var label = new UILabel
{
Font = UIFont.PreferredBody
};
This should automatically scale the fonts according to your Accessibility settings on iOS.
I have a very simple Xamarin forms app which contains a scrollview, and inside is a stacklayout.
When deployed on Windows, the mouse works correctly to scroll the scrollview with a scrollbar. However, touch/drag does not work at all to scroll the same control. Do I have to do something special to enable touch/drag to scroll? I figured this would just work.
I'm not sure even where to start troubleshooting.
I am targeting Windows 10. Other platforms optional at this point.
The structure of UI classes I have is this:
ContentPage.Content = StackLayout1
StackLayout1.Children = { StackLayout2, Scrollview }
StackLayout2 contains an entry field and two buttons
ScrollView, which is the problem, contains another StackLayout
Inside that I have some labels and some grids
Following is a simplified repro. Running in the android emulator on my (touch capable) dev machine scrolling with touch works, running in the Windows 8.1 emulator, scrolling only works with a mouse, not with touch.
public App() {
StackLayout sl = new StackLayout();
for (int i = 1; i < 20; i++) {
sl.Children.Add( new Label { Text = "Label1", FontSize = 50, HeightRequest = 100 } );
}
ScrollView sv = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand };
sv.Content = sl;
ContentPage cp = new ContentPage();
cp.Content = sv;
MainPage = cp;
}
Does Xamarin not handle Windows devices with touch, like Surface or other windows tablets? Or?
There is an overriden method from Activity which is: public boolean onTouchEvent(MotionEvent event)
This is the general method that interprets all the touch events from the whole screen.
As you know every View has its own onTouchEvent() method that you could implement in order to add some custom implementation.It appears that these touch events go from the "inside" elements to the "outside" elements. I mean parent-child relations.
So in our case, the ScrollView returns true when the touch events are a horizontal. The activity's touch event will be handled only if the ScrollView touch event is not handled by itself then you are fine. Otherwise you have to override and implement the on touch event of scroll view and in some cases you have to return false so as for the whole layout to implement it.
The solution is to update Xamarin v2.0.0.6482, which came with my VS 2015 template, to v2.1.0.6529. Updating is a bit of a pain because of this problem https://bugzilla.xamarin.com/show_bug.cgi?id=39721. Once I got that installed scrolling started working with no other changes.
Scrolling is broken in the older version, on Windows, verified by a dev on the Xamarin forums.
I am using the Hubtile Control provided in the Silverlight toolkit ( August) and I haven't been able to figure out how to pin the tiles to the homepage. Totally clueless and I have thoroughly searched everywhere with no luck. Help appreciated!
You use the ShellTile API as described on MSDN to add a secondary tile to the Start screen.
If you're using HubTile controls within your application, then you'll need to handle a touch gesture (e.g. Tap event) to determine which tile to pin, but it all depends on your app.
Here's the article that gives you answer in more details, including the code:
http://igrali.wordpress.com/2011/09/27/how-to-pin-a-hubtile-to-start-screen/
Basically, you create a new StandardTileData and then call ShellTile.Create. The information for the StandardTileData object should be passed from the HubTile object:
private void CreateLiveTile(HubTile hubtile)
{
StandardTileData LiveTile = new StandardTileData
{
BackgroundImage = ((System.Windows.Media.Imaging.BitmapImage)
hubtile.Source).UriSource,
Title = hubtile.Title,
BackTitle = hubtile.Title,
BackContent = hubtile.Message
};
Find more details in the article!
Regards
First, SelectedIndex is not exposed in markup, so you have to do it in code behind, right?
Second, I have set the binding in code behind:
Binding binding = new Binding("Main.PanoSelectedIndex.ObservedObject");
binding.Mode = BindingMode.TwoWay;
rootPano.SetBinding(Panorama.SelectedIndexProperty, binding);`
(ObservedObject implements iNotifyChanged)
The binding path points to my Main view model, and I can see that the PanoramaItem is updating the binding. However,the panorama does not respond when something else (a MVVM Light command) changes the binding. Any ideas?
Thanks,
Roger
To quote from the Windows Phone Developer FAQ
Panorama is designed so the user is in control, there fore you cannot set SelectedIndex programmatically, or force a navigation to a panorama item.
You can set the DefaultItem so that when your panorama is first launched, the panorama navigates to that item, but you can’t navigate programmatically beyond that. DefaultItem can also be used so that a back navigation feels like the item where the user was at did not change.
UPDATE: You can use the DefaultItem to save/restore the selection for a Panorama as shown below (code from Jeff Prosise's recent blog post):
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
// Save the Panorama control's SelectedIndex in page state
State["Index"] = PanoramaControl.SelectedIndex;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// Restore the Panorama control's SelectedIndex
if (State.ContainsKey("Index"))
PanoramaControl.DefaultItem = PanoramaControl.Items[(int)State["Index"]];
}
As far as I know SelectedIndex is a readonly property in Panorama ( Weired why WP7 SDK made it readonly). So you will get only UI change back to your VM, and you cant update UI through the VM propertychange.
And DefaultItem is the property which used to set the index programatically.
Again the issue of programatically setting an already instantiated Panorama is that, the alignment of the Title and Panoramaitem wont be in sync. Anyway I am not discouraging but there is still some chance of hack there.