Sub-MenuItems seem to align right by default - xaml

Every time I use a menu with MenuItems, the sub-MenuItems align right by default. They do so no matter what I put for the HorizontalAlignment property. Even when I type a relatively simple example:
<Grid>
<Menu Height="23" VerticalAlignment="Top">
<MenuItem Header="_File">
<MenuItem Header="_New" />
</MenuItem>
</Menu>
</Grid>
The "New" MenuItem aligns right relative to the "File" MenuItem. For what it's worth, it looks normal in the preview using Visual Studio, just not when I actually run it.

There is space on the left hand side of the text to accompany the IsCheckable checkbox. You can see it in action using the following code:
<MenuItem Header="_New" IsCheckable="True"/>
If you want to remove this spacing, consider using a ControlTemplate to override the default MenuItem template.

I apologize, apparently I didn't search hard enough for other posts with the same problem. This user had the same problem (and did a better job of illustrating it), and the solution posted there worked perfectly. The issue was that since my computer is optimized for touch technology, the default is to align sub-MenuItems so that right-handed users' hands won't get in the way.

Related

Separator tag not found in UWP XAML

I think the title says it all. When I try to use the <Separator /> tag to put a line in between elements in a stack panel in a UWP XAML app, I get this:
When I hover over the separator elements it says that The type Separator cannot be found and gives the error code XLS0414.
Any ideas?
I've looked at many websites and they all say that I need to use the separator tag for what I'm trying to do, but I can't use it...
There is no such thing as a Separator UIElement in UWP. Separator is a WPF construct, so if you're looking at many websites that all say you need to use the separator flag, they're probably referring to a WPF application or using some toolkit nuget package.
However, you can mimic a Separator using a couple of workarounds.
Use a Border that has a thickness defined on only one edge.
<Border BorderThickness="0,1,0,0" ... />
Use a Rectangle that is shaped like a separator
<Rectangle HorizontalAlignment="Stretch" Height="1" Fill="Black" />

Use an Icon Font in Xamarin Forms TabBar

I am just getting started with Xamarin Forms, so please excuse what may well be a rookie question...
I started out with a new Shell Forms App in Visual Studio, so some code was generated for me.
There is an AppShell page which contains a TabBar control. Inside this are Tab controls were I can set my ShellContent pages.
Each Tab has an Icon property, but this apparently only accepts PNG icons.
How can I use an icon font (which is already hooked up to display icons correctly as I am using them in the content of another page) for my Tab icons in Xaml?
I am using Xamarin.Forms 4.0.0.497661
You have to use FontImageSource to do that.
<Tab Title="MyTitle">
<Tab.Icon>
<FontImageSource FontFamily="{StaticResource IconFont}" Glyph="" Size="Small"/>
</Tab.Icon>
...
</Tab>
The solution below worked for me.
Copied the files from fontawesome inside Assets folder
fa-brands-400.ttf
fa-regular-400.ttf
fa-solid-900.ttf
Important the reference "Font Awesome 5 Brands" according to icon needed
<Tab.Icon>
<FontImageSource FontFamily="fa-brands-400.ttf#Font Awesome 5 Brands" Glyph=""/>
</Tab.Icon>
That's a great question. You can't use the tab icon property in a straight forward way to accept the icon font, unless you convert it into a PNG.
If you want to go that route, you can try this, you might have to deal with permissions for saving images. Worth a try!
You can do that with custom renderers as a workaround. Check this example on GitHub here: https://github.com/winstongubantes/Xamarin.Forms/tree/master/CustomIconizeFont

How to use TableView in Xamarin.Forms?

I am relatively new to the world of Xamarin.Forms and have a question with regard to Xamarin TableView.
I want to create a layout similar to the one shown below.
Question is, can I use TableView for this or is there an another option for this? Can anyone show this with XAML code please?
Thanks in advance.
Edit: Tabs in the bottom are not required.
I don't mean to be rude, but this is very easy to retrieve from the documentation pages and a bit of trying yourself.
To get you started, try this:
<TableView Intent="Settings">
<TableView.Root>
<TableView.Section>
<ImageCell Text="Invoice Customization" Source="Invoice_image.png" />
<ImageCell Text="Invoice Defaults" Source="Invoice_image.png" />
</TableView.Section>
<TableView.Section Title="Security">
<SwitchCell Text="Use Touch ID" />
</TableView.Section>
... etc.
</TableView.Root>
</TableView>
The arrows at the end of the cells and the footer text underneath the Security section are not possible with Xamarin.Forms out of the box, this will probably require you to write a custom renderer.

Windows 8 XAML Multilingual Translations

I've used the Multilingual Toolkit to translate my app and have been testing it using pseudo-language. It works fine for strings I have translated in code (C#) but I can't work out how to make it so that the tag in XAML is automatically translated.
I've been using http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh965329.aspx as a tutorial but I can't figure it out. I've also searched on Google but still no luck.
For example, I created a "Watermark" text box (which inherits from TextBox which shows some text in by default it the user has not entered any text and the item does not have focus. The XAML looks like this (I replaced generic positioning stuff with '...'):
<local:WatermarkTextbox x:Name="TitleTextBox" Watermark="MainPage_EnterATitle" ... Style="{StaticResource TextBoxStyle1}" />
As you can see it is setting a property called Watermark with a 'tag' of the resource name that is being translated using the Multilingual tool. I'm not sure how to get this to automatically translate.
Another example is using the bottom app bar buttons:
<Button x:Name="bottomAppBar_unpinFromStartButton" AutomationProperties.Name="MainPage_UnpinFromStart" Style="{StaticResource UnPinAppBarButtonStyle}" Click="bottomAppBar_unpinFromStartButton_Click"/>
And I can see in the link above that it says:
MediumButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name
But I'm not really sure where this is meant to go.
Even with a button, which seems like it would be the simplest to translate I can't get it to work. The XAML is:
<Button x:Name="RemovePhotoButton" x:Uid="MainPage_RemovePhoto" Content="" HorizontalAlignment="Center" Margin="222,0,974,78" Grid.Row="1" VerticalAlignment="Bottom" Width="170" Height="45"/>
But when ran in the app or viewed in the designed the button stays blank, with no text on it.
The Resources are set up like this:
And it is filling the translated documents fine:
I am able to translate it in C# using the code from the link above, just not using XAML.
Just wondering if anybody could help me out or point me in the right direction to solve this.
Thanks
First what i think is missing in the name of your resources is the property that you want to set. While never used it myself, i would understand it like this:
Your xaml needs to be changed to
<local:WatermarkTextbox x:Name="TitleTextBox" x:Uid="MainPage_EnterATitle" Watermark="" ... Style="{StaticResource TextBoxStyle1}" />
And your resource needs an entry with the key
MainPage_EnterATitle.Watermark
And about the part with the
MediumButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name
This is only used if the referenced property is an attached property. Like if your Watermark property would be attached not part of the control. But in your case its not important.

Windows 8 bottom app bar

I've been trying to get an App bar implemented in a WinRT metro app (C# / XAML), but don't know where to begin. I've tried using the <ApplicationBar/> tag and I get a Type not found error.
There's no help online, could someone update this post with the answer so that it'll serve as a reference to other programmers as well?
There's only a JavaScript sample which isn't of much help.
This should work:
<AppBar
VerticalAlignment="Bottom">
<Button
AutomationProperties.Name="Play"
Style="{StaticResource PlayAppBarButtonStyle}"
Command="{Binding PlayCommand}" />
</AppBar>
– you would put that in the layout root grid of your page.
*EDIT
Note: According to documentation - you should put it in Page.BottomAppBar property, although at least in Windows 8 Consumer Preview - it works fine when used in any Grid, which is convenient if your UI isn't tightly coupled to a Page control.
*EDIT 2, response from MSFT:
The recommended approach is to use the Page.BottomAppBar/TopAppBar properties.
There are known hit-testing issues in the Consumer Preview if AppBars are added without using these properties
The AppBars do not use the proper animations if they are added without using these properties
If AppBars are added as children of arbitrary elements then it's easier for multiple controls to attempt to create/modify AppBars, resulting in an inconsistent user experience
*EDIT 3
The CustomAppBar in WinRT XAML Toolkit can be used anywhere, animates based on Vertical/Horizontal-Alignment, can have other content overlaid on top of it and also has a CanOpen property that allows to block it from opening.
<Page.TopAppBar>
<AppBar>
<TextBlock x:Name="TextBlock1" Text="Sample Text" Margin="0,0,0,0" Height="Auto" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</AppBar>
</Page.TopAppBar>