How do I customize the content and location of a tooltip using Syncfusion in Xamarin? - xaml

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.

Related

WinUI HyperlinkButton is not displayed underlined

I am using the WinUI technology.
I would like to display a HyperlinkButton in my XAML.
The problem is that the HyperlinkButton is not displayed underlined.
But according to this documentation this should be the case / the default behavior: MSDN - HyperlinkButton Class
Here is what I have:
<HyperlinkButton Content="Example" Click="HyperlinkButton_Click" />
Neither I have any style that would affect how the button is displayed nor did I change a template.
What am I missing?
Thank you.
UPDATE
The problem exists in version 1.0.1 (march 2022) of Windows App SDK as well as in version 1.0.0 (november 2021), see windows-app-sdk/downloads
The template of the HyperlinkButton has changed in later versions of the Windows App SDK (1.0.0+) but apparently the documentation hasn't been updated.
You should still be able to use a Hyperlink element to get an underlined link though:
<TextBlock>
<Hyperlink Click="Hyperlink_Click">Example</Hyperlink>
</TextBlock>
HyperlinkButton missing underlined text is almost confirmed a bug.
As a workaround to add underline on the button text string, you can try the following way to display something with TextDecorations property as "Underline".
<HyperlinkButton Click="HyperlinkButton_Click">
<TextBlock Text="www.microsoft.com" TextDecorations="Underline" />
</HyperlinkButton>
Edit:
Finally, according to the issue,
The documentation needs updating to reflect the updated design for
HyperlinkButton first introduced in WinUI 2.6, see the WinUI Figma
toolkit for more info.

Using Resource files in XAML in Xamarin.Forms

I'm trying to use a resource file in my XAML. For some reason i keep getting the error of not finding the type Texts. Not sure what I'm doing wrong here.
XAML
<?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:local="clr-namespace:CashRegisterApp.Resources"
x:Class="CashRegisterApp.Start">
<ContentPage.Content>
<StackLayout
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" >
<Label Text="{x:Static local:Texts.Start}"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
RESX
Solution explorer
Creating RESX files within Shared projects is known to cause issues. You can see several lengthy posts in Xamarin Forums regarding this (here and here for example).
The easiest solution that will allow you to use the approach you want is to create a new .NET Standard Library of PCL library in your solution, create your RESX files there and set their visibility to public. Then you will be able to utilize them using the x:Static syntax as expected.
Many developers use an alternative in the form of a custom markup extension like the solution by ClaudioPereira in this forum. This simplifies the syntax even more.
Finally, for most detailed information on Xamarin.Forms you can refer to the official documentation.
I had this issue too and I hope this answer helps people in the future with this issue.
Following this guide taught me how to set up resx files in Xamarin forms.
Their TranslateExtension allows for referring to the resx file directly from Xaml.
Unfortunately, in its raw form it doesn't pick up a runtime change in locales.
This is fixable by changing their "Localize" class (on the native platforms) to keep a reference of the CultureInfo when changed via the SetLocale method and return it when the GetCurrentCultureInfo method is called.

Conditional XAML causes XBF generator error

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.

How to bind an event to a command in a Universal App using the MVVM pattern?

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.

Theme-aware XAML resources in a WP7 project

I'm making a Windows Phone 7 application and I'm a bit confused with dark/light themes.
With a panorama, you very often set a background image. The issue is it's very hard to make a picture which is right for both dark and light themes. How are we supposed to proceed?
Is there a way to force a dark/light theme for a panorama? This will avoid making theme-specific panorama background pictures. Then how do I do? I found xaml files in C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Design. If this is a right way to proceed, how can I import them for my panorama?
Or if there's no way (or if it's wrong) to force a dark/light theme: how to write conditional XAML to set correct resources? Now I have the following XAML (default.xaml) which is fine with the dark theme:
<ImageBrush x:Key="PageBackground" ImageSource="Resources/PageBackground.png" Stretch="None" />
<ImageBrush x:Key="PanoramaBackground" ImageSource="Resources/PanoramaBackground.png" Stretch="None" />
But when I use a light theme, black controls and black texts are hard to read with my dark background pictures. So I made different pictures that I can use this way:
<ImageBrush x:Key="PageBackground" ImageSource="Resources/PageBackgroundLight.png" Stretch="None" />
<ImageBrush x:Key="PanoramaBackground" ImageSource="Resources/PanoramaBackgroundLight.png" Stretch="None" />
Now my issue is to make XAML conditional to declare the right thing depending on the current theme.
I found no relevant way on the Internet. I would prefer not to use code or code-behind for that because I believe XAML is able to do this (I just don't know how).
EDIT: Code snippet to load a xaml file as ResourceDictionary
string xaml = null;
StreamResourceInfo xamlInfo = Application.GetResourceStream(new Uri("light.xaml", UriKind.Relative));
using (StreamReader sr = new StreamReader(xamlInfo.Stream))
xaml = sr.ReadToEnd();
dic = (ResourceDictionary)XamlReader.Load(xaml);
this.Resources.MergedDictionaries.Add(dic);
To force a dark or white theme you can indeed use the styles defined in the folder you pointed out. Copy and Paste the rules you need to your App.xaml (just PhoneForegroundColor, PhoneBackgroundColor and the related Brushes would be a good start).
It's probably better though to stay "theme-aware" and load a different image for light and dark themes. Here is an article explaining how to do this: http://blog.jayway.com/2010/12/16/theme-aware-panorama-background-in-windows-phone-7/
There is another possibility I've found: You can use the Coding4Fun Toolkit Converter according to these instructions. However, I'm unable to use correctly use them.
Another possibiliy is to use an OpacityMask. But this only works for black/white images :/
Yousef's solution looks interesting. but it takes too much time to load. The image will be changed round about 1s after the app started. I've tested this on a Nokia 820. I've moved the call for setting the DataContext in a Loaded Event, which was called much later. Now the call takes place in the constructor, so the image will be already set when the application displays it. However, it still adds more loading time :( Any suggestions on how to improve this?