Concatenating binding data in XAML frontend with .NET maui not working - c#

I am trying to add an "R" in front of my binding variable in my XAML frontend of my .NET maui project.
Below is the line of code:
<Label Text="{Binding FundsTotal, StringFormat=R{0}}" Margin="0, 20, 0, 0" FontFamily="PoppinsRegular" FontSize="35" HorizontalTextAlignment="Center" TextColor="White"></Label>
The String formatting works initially but as soon as I stop and start the project again, the R no longer shows up. Any suggestions?

Related

How can we wrap words in a lable in .net maui 7

Here is the .Net Maui code
<Label x:Name="LblName" FontSize="Default" LineBreakMode="WordWrap" TextColor="White" ></Label>
I'm trying to wrap the text but so far, nothing seems to be working. I've used all of the "LineBreakMode(s)" in conjunction with the "MaxLines".
The data in label is coming from the code behind file using the "LblName".
I've used all of the "LineBreakMode(s)" in conjunction with the "MaxLines".

Xamarin.Forms.Pages.ListDataPage not loading Data from AzureEasyTableSource

I am trying to use the new Xamarin.Forms.Pages.ListDataPage control that is currently in Preview.
I have followed the instructions on the getting started page Getting Started with DataPages to set up an AzureEasyTableSource.
The app compiles and runs, but this.DataSource.Data.Count always returns 0, on both iOS and Android.
Bellow is the Views XAML
<?xml version="1.0" encoding="UTF-8"?>
<p:ListDataPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Sparrow"
xmlns:azure="clr-namespace:Xamarin.Forms.Pages.Azure;assembly=Xamarin.Forms.Pages.Azure"
xmlns:p="clr-namespace:Xamarin.Forms.Pages;assembly=Xamarin.Forms.Pages"
x:Class="Sparrow.NewsPage" StyleClass="Event" Title="News" BindingContext="This">
<p:ListDataPage.DataSource>
<azure:AzureDataSource>
<azure:AzureDataSource.Source>
<azure:AzureEasyTableSource TableName="NewsItem"
Uri="https://<<AppName>>.azurewebsites.net"/>
</azure:AzureDataSource.Source>
</azure:AzureDataSource>
</p:ListDataPage.DataSource>
<p:ListDataPage.DefaultItemTemplate>
<DataTemplate>
<ViewCell>
<p:ListItemControl
Title="{ Binding Value[headline] }"
Detail="{ Binding Value[newsBody] }"
DataSource="{ Binding Value }"
HeightRequest="30"
/>
</ViewCell>
</DataTemplate>
</p:ListDataPage.DefaultItemTemplate>
</p:ListDataPage>
A Wireshark capture and the App Service streaming logs show that the server is receiving and responding to the requests, but the application fails to process the data.
It looks like perhaps your data bindings are a problem here as they should correspond with the values that are coming in and need special syntax. Here is an example of mine taken from my OCR sample: https://github.com/jamesmontemagno/app-ocr-functions:
<p:CardView
Margin="10"
Text="Total Amount from OCR:"
Detail="{p:DataSourceBinding Total}"
ImageSource="{p:DataSourceBinding Url}"
DataSource="{Binding Value}"
HeightRequest="250"/>
</ViewCell>
You must use the p:DataSourceBinding to the name of it.

Set Label HeightRequest automatically depending on how much space the text needs

I have a Label inside a StackLayout inside a Frame:
<Frame Grid.Row="0" Margin="0, 0, -10, 0" OutlineColor="Transparent" HasShadow="False" Grid.Column="1" BackgroundColor="{StaticResource rightBubbleColor}">
<StackLayout>
<Label
Style="{StaticResource rightBubbleStyle}"
TextColor="{StaticResource rightBubbleFontColor}"
Text="{Binding message}" />
</StackLayout>
</Frame>
This gives me this result:
The problem here is that the last message actually has more text which would need 6 rows to display the whole text.
If I set a value for HeightRequest for the Label, it changes the height of the Frame as well. For example if I set a value of 150, I get this result:
I need to dynamically set a value for HeightRequest depending on how much height the Text needs.
Does anyone know how I can achieve that (preferably in xaml) or is this even a wrong approach to my problem?
Edit 1:
Removing the style from the Label doesn't solve the problem. It only occurs on UWP. Note that I don't have a Windows Phone to test it, the problem occurs on my local machine (Windows 10 Desktop).
Edit 2:
According to the Xamarin documentation, the height should be autosized dependon on the content:
When the app developer sets the ListView.HasUnevenRows property to true, the behavior of the list view still depends on the ListView.RowHeight property. First, if the developer either does not set the ListView.RowHeight property or sets it to -1, list view items are autosized to fit their contents. This is the desired behavior and the intended use case for a ListView.HasUnevenRows value of true, as noted above.
I found a solution. This was the problem:
<RowDefinition Height="*" />
I set the value to Auto and now it's working. Strange that it has a different behaviour on iOS and Android tho.

WindowsFormsHost error IsRedirected is not found?

I am adding a WINFORM chart to my WPF project using
System.Windows.Forms.Integration.WindowsFormsHost
I am trying to work around the "airspace" rendering issue where the host is always rendered as the top most element the window. The workaround I am using sets
IsRedireced = "true"
When I insert this into my XMAL code:
<Grid x:Name="ssCurveChartGrid" Grid.Column="1" Margin="110,30,160,306" Grid.ColumnSpan="4" RenderTransformOrigin="0.479,0.186">
<WindowsFormsHost IsRedirected =" "true">
</WindowsFormsHost>
</Grid>
or my code behind:
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
host.IsRedirected = "true";
I get the following error:
The property 'IsRedirected' was not found in type 'WindowsFormsHost'
Here is a screenshot:
Can anyone help explain why this is happening? I relay need to display an element on top of my WINFORM chart!
Thanks
EDIT:
Code was taken from MSDN site: http://msdn.microsoft.com/en-us/library/ms752027.aspx
From MSDN:
"By default, visible WindowsFormsHost elements are always drawn on top of other WPF elements, and they are unaffected by z-order. To enable z-ordering, set the IsRedirected property of the WindowsFormsHost to true and the CompositionMode property to Full or OutputOnly.
To see the default z-order behavior"
"Copy the following XAML into the Grid element."
<!-- Z-order demonstration. -->
<Canvas Grid.Row="1" Grid.Column="1">
<WindowsFormsHost Canvas.Top="20" Canvas.Left="20" Background="Yellow">
<wf:Button Text="Windows Forms control" FlatStyle="Flat"/>
</WindowsFormsHost>
<Label Content="A WPF label" FontSize="24"/>
</Canvas>
Press F5 to build and run the application. The WindowsFormsHost element is painted over the label element.
"To see the z-order behavior when IsRedirected is true"
Replace the previous z-order example with the following XAML.
XAML
<!-- Z-order demonstration. -->
<Canvas Grid.Row="1" Grid.Column="1">
<WindowsFormsHost IsRedirected="True" CompositionMode="Full" Canvas.Top="20" Canvas.Left="20" Background="Yellow">
<wf:Button Text="Windows Forms control" FlatStyle="Flat"/>
</WindowsFormsHost>
<Label Content="A WPF label" FontSize="24"/>
</Canvas>
Press F5 to build and run the application. The label element is painted over the WindowsFormsHost element.
Microsoft .NET Framework 4.5 Beta Readme
1.3.10 Windows Presentation Foundation (WPF)
1.3.10.1 HwndHost feature has been removed from WPF in the .NET Framework 4.5 Beta
The .NET Framework 4.5 Developer Preview included a WPF HwndHost redirection feature. However, this feature had several known issues and has been removed from the .NET Framework 4.5 Beta. It will not be included in any future releases.
To resolve this issue:
No workaround is available.
(emphasis added)
Which .Net Framework are you using here. IsRedirected for WindowsFormHost is released with Framework 4.5

Issue in displaying "-" symbol in calculator application in C# WPF

Hi i am trying to learn windows presentation foundation WPF and was trying to develop the simplest application Calculator. But i am having issue in displaying the '-' when i substract a higher value from smaller. For eg. if i do something like this "10 - 20" the output should be "-10" in the screen i.e. textbox. But it is displaying "10-". Somehow the '-' is coming in the end. my xaml code for textbox looks like following:
<TextBox Height="33" HorizontalAlignment="Left" Name="outputbox"
VerticalAlignment="Top" Width="278"
FontFamily="Tahoma" FontSize="18"
FlowDirection="righttoleft" IsReadOnly="True" />
and the code for doing substraction and display looks something like this
if (entry1 > entry2)
{
outputbox.Text = (entry1 - entry2).ToString();
}
else
{
outputbox.Text = "-" + (entry2 - entry1).ToString();
}
while debugging it shows the proper string as "-10" but while displaying in the textbox it is showing the string "10-". Any idea about what is missing???
Just remove the FlowDirection attribute from your TextBox and your result will be fine.
<TextBox Height="33"
HorizontalAlignment="Left"
Name="outputbox" VerticalAlignment="Top"
Width="278"
FontFamily="Tahoma"
FontSize="18" IsReadOnly="True" />
Or you may specify FlowDirection="LeftToRight" which is the default for the TextBox
Thanks All. I removed the "FlowDirection" property and it displayed the proper "-10" but the text was now displayed on the left side of textbox. So i used the "TextAlignment = right" property and it seems to be working fine. Thanks again all of you.

Categories