I am trying to set the Icon property of MenuFlyoutItem on the UWP. As this is only available in contract version 4, I wanted to use conditional XAML statements in form of the IsApiContractPresent statement. Doing this, I came up with this code:
<MenuFlyout>
<MenuFlyoutItem Text="Open">
<contract4Present:MenuFlyoutItem.Icon>
<FontIcon Glyph=""/>
</contract4Present:MenuFlyoutItem.Icon>
</MenuFlyoutItem>
</MenuFlyout>
and added this line in the definition of my page:
xmlns:contract4Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,5)"
Sadly, Visual Studio is now not able to compile the project anymore, with this error message:
The XAML Binary Format (XBF) generator reported syntax error '0x09C4' : Property Not Found
Strangely, the same errors comes up, when I use the minimal example given in the documentation
<TextBlock contract5NotPresent:Text="Hello, World"
contract5Present:Text="Hello, Fall Creators Update"/>
How can I solve this error? Or is this even a bug of Visual Studio?
Apparently, this functions is only available for Minimum Build versions > 15063. Otherwise, you must use version adaptive code, and not XAML.
Related
I am trying to add TeachingTip to Xaml file in a usual way:
<TeachingTip/>
But I get an error "The type 'TeachingTip' was not found".
I tried to add programmatically in cpp file (C++/CX):
TeachingTip^ tip = ref new TeachingTip();
The error is: "Identifier 'TeachingTip' is undefined".
All other controls work well.
The TechingTip control is part of the Windows UI Library, not Windows. As such it resides in namespace Microsoft.UI.Xaml.Controls (as opposed to Windows.UI.Xaml.Controls). To reference that control in XAML, you'll have to use the correct namespace. Getting started with the Windows UI Library has detailed instructions.
The following XAML fragment should work:
<Page x:Class="..."
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
...
>
<muxc:TeachingTip/>
...
</Page>
Likewise, when referencing the control in code, you'll have to specify the correct namespace.
I'm setting up a stacking column chart in XAML using Syncfusion for Xamarin in Visual Studio 2017. I've tried adding custom text according to the example here, but I run into an exception when the tooltip is activated. Here's the code I'm using:
<chart:SfChart.Series>
<chart:StackingColumnSeries EnableTooltip="True"
Width="0.5"
ItemsSource="{Binding TankLevels}"
XBindingPath="Name" YBindingPath="Level1">
<chart:StackingColumnSeries.TooltipTemplate>
<DataTemplate>
<StackLayout>
<Label Text="test"></Label>
</StackLayout>
</DataTemplate>
</chart:StackingColumnSeries.TooltipTemplate>
<chart:BarSeries.ColorModel>
<chart:ChartColorModel Palette="Custom" CustomBrushes="{Binding WaterColor}">
</chart:ChartColorModel>
</chart:BarSeries.ColorModel>
</chart:StackingColumnSeries>
I have analyzed your code snippet and prepared a sample based on it, and the sample can be downloaded from the link below.
Sample: 215585
I am afraid I was not able to reproduce the reported issue, it is working fine. Can you please provide more information like a stack trace on the exception?
Thanks,
Michael
Note: I work for Syncfusion
The issue was that I was using an outdated version of Syncfusion's Xamarin Controls. I didn't have any more issues after updating to the newest version.
Running Visual Studio for Mac with Forms version 3.1.0.637273.
The documentation says to do this in the code-behind:
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
...
On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
Or this in the Xaml:
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="true"
I've done both, and both give the same error:
Error CS1061: 'IPlatformElementConfiguration<iOS, Page>' does not contain a definition for 'SetUseSafeArea'
I get no error from just doing this:
On<Xamarin.Forms.PlatformConfiguration.iOS>();
Which does me no good, but at least it proves that I'm accessing the PlatformConfiguration.iOS stuff without an error.
Why isn't my code recognizing anything having to do with SafeArea stuff at all?
I hope somebody can help.
I've spent some time researching the best way to bind an event to a ViewModel command using the MVVM pattern when developing a Universal App. I'm using MVVM Light.
As a test I'm using the SelectionChanged event of a ComboBox.
I've read a few people that have pinched the Behaviours SDK from the Windows 8.1 / WinRT framework and had some success with that. I have also included the Universal App behaviours SDK in my project and tried the following (put together from Windows 8.1 examples but using the UWP SDK).
XAML
<Page
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core" />
...
<ComboBox ItemsSource="{Binding InputQuantities}">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="SelectionChanged">
<core:InvokeCommandAction Command="{Binding SomeComboBoxCommand}" CommandParameter="Foo" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ComboBox>
View Model
public RelayCommand SomeComboBoxCommand {get; set;}
However, the core:InvokeCommandAction isnt part of the Behaviours SDK and i get Invalid Type: expected type is 'Microsoft.Xaml.Interactivity.ActionCollection'. I've tried to use an ActionCollection.... but I'm not sure I know what I'm doing with that.
Ive successfully got it to work with compiled bindings and using Laurent's Blog Post:
XAML
<ComboBox ItemsSource="{Binding InputQuantities}" SelectionChanged="{x:Bind Vm.SomeComboBoxCommand }" />
View Model
public void SomeComboBoxCommand(object sender, SelectionChangedEventArgs e){//do stuff}
I know this isnt what Laurent is intending to demonstrate here and I think doing this is breaking the decoupling of the view and VM by then having to reference a UI component in my view model to get the selected item. But I've seen references to doing this during my research.
So how can I get this working using The Universal App interaction behaviours, if that's the right way to do it of course?
Update 1.
This is what I attempted to add, believing, incorrectly that I was adding the universal app behaviours SDK. I didn't notice at the time that it was targeting Windows 8.1.
However, my questions still stands: Why wont the InvokeActioncommandwork and why is it throwing the mentioned error? I will look at the other posts as soon as I get to work.
Update 2
After testing this on my works PC (exact same code as above, 1st example and the same behaviours SDK) it works fine and I'm getting the behaviour that I would expect. I need to test again on my home PC to see what has gone wrong. (Thanks to Justin XL for sticking with me)
Update 3
For completeness, after returning home I got the latest version of my project (from being checked in on my works PC) and it now also works on my home PC. I'm not sure what state my Visual Studio was in but it had sufficiently confused me enough to post this question. At least this should serve as a document on how to do what is described in the title. Thanks for all your help.
We seem to be getting this question a lot lately, in several different variants...
I'm not familiar with Universal App but is there any specific reason you're trying to use an event? WPF/Silverlight etc are designed to be data driven, all you need to do is bind the ComboBox's SelectedItem member to a property in your view model and the setter will get called whenever the user selects a new item. Often times you have to do exactly the same processing in response to other parts of your view model changing it (e.g. in Master-Child views) so having that logic in a single place generally makes for a much cleaner architecture.
Check this link: MVVM EventBinding Library ,explains about MVVM EventBinding. This purely decouples the View & View model & pass only the arguements to the command.
I have a reasonably large Silveright 3.0 project on the go, and I'm having issues accessing a couple of custom font resources from within one of the assemblies.
I've got a working test solution where I have added a custom font as a resource, and can access it fine from XAML using:
<TextBlock Text="Test" FontFamily="FontName.ttf#Font Name" />
The test solution consists of the TestProject.Application and the TestProject.Application.Web projects, with all the fun and games obviously in the TestProject.Application project
However, when I try this in my main solution, the fonts refuse to show in the correct type face (instead showing in the default font). There's no difference in the way the font has been added to project between the test solution and the main solution, and the XAML is identical.
However, there is a solution layout difference. In the main solution, as well as having a MainApp.Application and MainApp.Application.Web project, I also have a MainApp.Application.ViewModel project and a MainApp.Application.Views project, and the problem piece of XAML is the in the MainApp.Application.Views project (not the .Application project like the test solution).
I've tried putting the font into either the .Application or .Application.Views project, tried changing the Build Action to Content, Embedded Resource etc, all to no avail.
So, is there an issue accessing font resources from a child assembly that I don't know about, or has anyone successfully done this?
My long term need will be to have the valid custom fonts being stored as resources in a separate .Application.FontLibrary assembly that will be on-demand downloaded and cached, and the XAML controls in the .Application.Views project will need to reference this FontLibrary assembly to get the valid fonts. I've also tried xcreating this separate font library assembly, and I can't seem to get the fonts from the second assembly.
As some additional information, I've also tried the following font referencing approaches:
<TextBlock Text="Test" FontFamily="/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/MainApp.Application.Views;/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/MainApp.Application.Views;component/FontName.ttf#Font Name" />
And a few similar variants with different assembly references/sub directories/random semi colons.
And so far nothing works... anyone struck this (and preferably solved it)?
This code works for me:
... FontFamily="/(DLL);Component/(DIR-optional)/(Font_file)#(Font_name)"/> ...