Below image you see the red circle indicators where it's only possible to click and radiobutton works, but I want to scoop them to the correct place(to the left so it's aligned with UI), which I don't know how. I tried TranslationY=-80 but it didn't work.
Styles.xaml:
<ControlTemplate x:Key="RadioButtonTemplate">
<Frame BorderColor="#F3F2F1" CornerRadius="2" BackgroundColor="#F3F2F1" HasShadow="False" HeightRequest="80" WidthRequest="80" HorizontalOptions="Start" VerticalOptions="Start" Padding="0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroupList>
<VisualStateGroup x:Name="CheckedStates">
<VisualState x:Name="Checked">
<VisualState.Setters>
<Setter Property="BorderColor" Value="#FF3300" />
<Setter TargetName="check" Property="Opacity" Value="1" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Unchecked">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="#F3F2F1" />
<Setter Property="BorderColor" Value="#F3F2F1" />
<Setter TargetName="check" Property="Opacity" Value="0" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</VisualStateManager.VisualStateGroups>
<Grid Margin="4" WidthRequest="80">
<Grid WidthRequest="18" HeightRequest="18" HorizontalOptions="End" VerticalOptions="Start">
<Ellipse Stroke="Blue" Fill="White" WidthRequest="16" HeightRequest="16" HorizontalOptions="Center" VerticalOptions="Center" />
<Ellipse x:Name="check" Fill="Blue" WidthRequest="8" HeightRequest="8" HorizontalOptions="Center" VerticalOptions="Center" />
</Grid>
<ContentPresenter />
</Grid>
</Frame>
</ControlTemplate>
<Style TargetType="RadioButton">
<Setter Property="ControlTemplate" Value="{StaticResource RadioButtonTemplate}" />
</Style>
MyPage.xaml:
<StackLayout Spacing="3">
<Label Text="{Binding SelectedTheme, StringFormat='Theme: {0}'}" FontSize="20" />
<Grid ColumnDefinitions="*,*,*" RadioButtonGroup.GroupName="themes" RadioButtonGroup.SelectedValue="{Binding SelectedTheme, Mode=TwoWay}">
<RadioButton Value="{x:Static am:AppTheme.Unspecified}" CheckedChanged="RadioButton_CheckedChanged">
<RadioButton.Content>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Image Scale="0.75" Source="{FontImage FontFamily=FAS, Glyph={x:Static fontawesome:FontAwesomeIcons.Gear}, Color=#323130}" />
<Label FontSize="Small" Text="System" TextColor="#323130" />
</StackLayout>
</RadioButton.Content>
</RadioButton>
<RadioButton Value="{x:Static am:AppTheme.Light}" Grid.Column="1" CheckedChanged="RadioButton_CheckedChanged">
<RadioButton.Content>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Image Scale="0.75" Source="{FontImage FontFamily=FAS, Glyph={x:Static fontawesome:FontAwesomeIcons.Sun}, Color=#323130}" />
<Label FontSize="Small" Text="Light" TextColor="#323130" />
</StackLayout>
</RadioButton.Content>
</RadioButton>
<RadioButton Value="{x:Static am:AppTheme.Dark}" Grid.Column="2" CheckedChanged="RadioButton_CheckedChanged">
<RadioButton.Content>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Image Scale="0.75" Source="{FontImage FontFamily=FAS, Glyph={x:Static fontawesome:FontAwesomeIcons.Moon}, Color=#323130}" />
<Label FontSize="Small" Text="Dark" TextColor="#323130" />
</StackLayout>
</RadioButton.Content>
</RadioButton>
</Grid>
</StackLayout>
It's hard to say it is a potential issue or by design .
To solve the problem/as a workaround , you can add a TapGestureRecognizer on ContentPresenter to enable the RadioButton manually .
Sample code
//xaml
<ContentPresenter >
<ContentPresenter.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</ContentPresenter.GestureRecognizers>
</ContentPresenter>
//code behind
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
ContentPresenter cp = sender as ContentPresenter;
var button = cp.Content.Parent as RadioButton;
button.IsChecked = true;
}
Related
I am using radio button control with customised radio button selection colors in .Net Maui.But when changing the selection , it doesn't fire CheckedChanged event.
Here is the code snippet,
View
<StackLayout
x:Name="SexRadioGroup"
Grid.Row="10"
Margin="24,12,0,0"
Orientation="Horizontal"
RadioButtonGroup.GroupName="SexRadioGroup"
Spacing="40">
<RadioButton
GroupName="SexRadioGroup"
IsChecked="True"
Value="Male">
<RadioButton.Content>
<StackLayout>
<Label
Margin="30,0,0,0"
Text="Male"
TextColor="{StaticResource FieldNameTextColor}"
VerticalOptions="Start" />
</StackLayout>
</RadioButton.Content>
</RadioButton>
<RadioButton
CheckedChanged="SexRadioButton_CheckedChanged"
GroupName="SexRadioGroup"
Value="Female">
<RadioButton.Content>
<StackLayout>
<Label
Margin="30,0,0,0"
Text="Female"
TextColor="{StaticResource FieldNameTextColor}"
VerticalOptions="Start" />
</StackLayout>
</RadioButton.Content>
</RadioButton>
</StackLayout>
Code behind file
private void SexRadioButton_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
}
Style(RadioButton template)
<ControlTemplate x:Key="RadioButtonTemplate">
<Frame
Padding="0"
BackgroundColor="#F3F2F1"
BorderColor="#F3F2F1"
HasShadow="False"
HeightRequest="100"
HorizontalOptions="Start"
VerticalOptions="Start"
WidthRequest="100">
<Grid Margin="4" WidthRequest="100">
<Grid
HeightRequest="18"
HorizontalOptions="End"
VerticalOptions="Start"
WidthRequest="18">
<Ellipse
Fill="White"
HeightRequest="16"
HorizontalOptions="Center"
Stroke="Blue"
VerticalOptions="Center"
WidthRequest="16" />
<Ellipse
x:Name="check"
Fill="Blue"
HeightRequest="8"
HorizontalOptions="Center"
VerticalOptions="Center"
WidthRequest="8" />
</Grid>
<ContentPresenter />
</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroupList>
<VisualStateGroup x:Name="CheckedStates">
<VisualState x:Name="Checked">
<VisualState.Setters>
<Setter Property="BorderColor" Value="#FF3300" />
<Setter TargetName="check" Property="Opacity" Value="1" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Unchecked">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="#F3F2F1" />
<Setter Property="BorderColor" Value="#F3F2F1" />
<Setter TargetName="check" Property="Opacity" Value="0" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</VisualStateManager.VisualStateGroups>
</Frame>
</ControlTemplate>
<Style TargetType="RadioButton">
<Setter Property="ControlTemplate" Value="{StaticResource RadioButtonTemplate}" />
</Style>
Is there any way to use renderer to change the selection and unselection color of the radio button by renderers?
The cause is the clicked event has been dealt with by the Frame, not the radio button. So you can add the TapGestureRecognizer to the Frame. I use the control template in the App.xaml. Such as:
<ControlTemplate x:Key="RadioButtonTemplate">
<Frame
Padding="0"
BackgroundColor="#F3F2F1"
BorderColor="#F3F2F1"
HasShadow="False"
HeightRequest="100"
HorizontalOptions="Start"
VerticalOptions="Start"
WidthRequest="100">
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</Frame.GestureRecognizers>
And in the App.cs:
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
Frame frame = sender as Frame;
RadioButton button = (RadioButton)frame.Parent;
button.IsChecked = true;
}
And then, the radio button checked changed event will be hit when you click it. (Note: On the windows platform, it can work without the TapGestureRecognizer.)
I have a ControlTemplate to modify the appearance of a radioButton in Xamarin.Forms.
I borrowed/updated it from https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/radiobutton#redefine-radiobutton-appearance
It looks great, and the appearance is perfect when the page is created.
I want the image in the radiobutton to change depending on a binding, which it does not do.
The binding property gets modified, OnPropertyChanged() gets called, but the binding is not getting triggered.
Here is the general appearance (with two of these RadioButtons side by side)
Again, the appearance and the Converter and everything work just fine, but only when the page is first drawn.
Here is the ControlTemplate
<ControlTemplate x:Key="RadioButtonTemplate">
<Frame
BackgroundColor="#30888888"
HasShadow="False"
HeightRequest="{TemplateBinding HeightRequest}"
WidthRequest="{TemplateBinding WidthRequest}"
HorizontalOptions="Start"
VerticalOptions="StartAndExpand"
Padding="0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroupList>
<VisualStateGroup x:Name="CheckedStates">
<VisualState x:Name="Checked">
<VisualState.Setters>
<Setter Property="BorderColor" Value="Accent" />
<Setter TargetName="check"
Property="Opacity"
Value="1" />
<Setter TargetName="checkrim"
Property="Opacity"
Value="1" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Unchecked">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{DynamicResource TransparentBackgroundColour}" />
<Setter Property="BorderColor" Value="Transparent" />
<Setter TargetName="check"
Property="Opacity"
Value="0" />
<Setter TargetName="checkrim"
Property="Opacity"
Value="0" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</VisualStateManager.VisualStateGroups>
<Grid Margin="4"
WidthRequest="100">
<ContentPresenter Margin="6" />
<Grid WidthRequest="20"
HeightRequest="20"
Padding="0"
HorizontalOptions="Start"
VerticalOptions="Start">
<Ellipse x:Name="unckecd"
Stroke="White"
StrokeThickness="2"
Fill="Transparent"
Margin="0"
WidthRequest="20" HeightRequest="20"
HorizontalOptions="Center" VerticalOptions="Center" />
<Ellipse x:Name="checkrim"
Stroke="Accent"
StrokeThickness="2"
Fill="Transparent"
Margin="0"
WidthRequest="20" HeightRequest="20"
HorizontalOptions="Center" VerticalOptions="Center" />
<Ellipse x:Name="check"
Fill="Accent"
Margin="1,1,0,0"
WidthRequest="10" HeightRequest="10"
HorizontalOptions="Center" VerticalOptions="Center" />
</Grid>
</Grid>
</Frame>
</ControlTemplate>
And the Style of my RadioButton
<Style x:Key="FancyRadioButton" TargetType="RadioButton">
<Setter Property="ControlTemplate"
Value="{DynamicResource RadioButtonTemplate}" />
</Style>
And my RadioButton
<RadioButton Style="{StaticResource FancyRadioButton}"
Value="{x:Static gdl90Types:UdpTransmitMode.UdpUnicast}"
WidthRequest="150"
HeightRequest="103">
<RadioButton.Content>
<StackLayout VerticalOptions="Start" Spacing="0" Margin="0, -3">
<Image Source="{Binding Source=ColourPresetSetting,
ConverterParameter=unicast,
Converter={StaticResource ResourceImageFromThemeConverter}}"
Margin="22,0"
Aspect="AspectFit"
/>
<Label Text="UDP UNICAST" TextColor="{DynamicResource MediumContrastTextColour}" />
</StackLayout>
</RadioButton.Content>
All I want is for the Image in the RadioButton to notice the property ColourPresetSetting changing, to update the image.
It does it when first drawn, but no longer after that.
Am I missing something obvious?
I have different Buttons that I want to put inside the <Frame> control, all this with the aim of avoiding the overflow of the image within the <ListView>, but when putting the HorizontalOptions and VerticalOptions property in FillAndExpand is not filling the Frame, I attached an image of the problem
How can I make the <Button> inside the <Frame> fill the space? I have tried to give the Columns and Rows the Auto property and I have not succeeded.
How can I keep the size of the button (Height and Width) but without losing the frame?
How can I fill and expand the button inside a Frame?
Any help for me?
VIEW.XAML:
<ListView
ItemsSource="{Binding ListaInventario}"
SelectionMode="None"
VerticalOptions="FillAndExpand"
IsRefreshing="{Binding IsRefreshing, Mode=TwoWay}"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout
Margin="0,4,0,0"
Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label
Text="{Binding Id}"
FontSize="Small"
HorizontalOptions="Center"
FontAttributes="Bold"
HeightRequest="39"
VerticalTextAlignment="Start"
TextColor="{StaticResource das.color.texto}"
Grid.Column="0"
Grid.Row="0">
</Label>
<Label
Text="{Binding NombreComercial}"
HorizontalOptions="Start"
FontSize="Small"
MaxLines="3"
HeightRequest="39"
TextColor="{StaticResource das.color.texto}"
VerticalOptions="Start"
Grid.Column="1"
Grid.Row="0">
</Label>
<Frame
HorizontalOptions="End"
BackgroundColor="Transparent"
Grid.Column="2"
Grid.Row="0">
<Button
ImageSource="ic_pdf"
HeightRequest="35"
WidthRequest="50"
BackgroundColor="{StaticResource das.color.estado_primary}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Command="{Binding HDSSisquimCommand}"/>
</Frame>
</Grid>
<!---->
<!--CANTIDAD-->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
Margin="0,1,0,2">
<StackLayout
Orientation="Horizontal"
HorizontalOptions="Start"
Margin="0,0,3,0">
<Label
HorizontalOptions="Start"
HorizontalTextAlignment="Start"
VerticalOptions="End"
VerticalTextAlignment="Center"
Text="Cantidad: "
FontAttributes="Bold"
FontSize="Small"
HeightRequest="35"
IsEnabled="{Binding EnabledEstimadoEntry}"></Label>
<Entry
HorizontalOptions="FillAndExpand"
Placeholder="Cantidad"
Keyboard="Numeric"
HorizontalTextAlignment="Center"
MaxLength="4"
FontSize="Small"
HeightRequest="35"
Text="{Binding CantidadDecimal}"
IsEnabled="{Binding EnabledContenedorEntry}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStatesEntry">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightGray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Entry>
</StackLayout>
<!--UNIDAD-->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand">
<Label
HorizontalOptions="Start"
HorizontalTextAlignment="Start"
VerticalOptions="End"
VerticalTextAlignment="Center"
Text="Unidad: "
FontAttributes="Bold"
FontSize="Small"
HeightRequest="35"
IsEnabled="{Binding EnabledEstimadoEntry}"></Label>
<Picker
iOSSpecific:Picker.UpdateMode = "WhenFinished"
ItemsSource="{Binding ListaUnidadesMedida}"
SelectedItem="{Binding SelectedUnidadMedida}"
ItemDisplayBinding="{Binding NombreCorto}"
Title="Unidad"
FontSize="Small"
HeightRequest="35"
HorizontalOptions="FillAndExpand"
IsEnabled="{Binding EnabledContenedor}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStatesPicker">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightGray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Picker>
</StackLayout>
</StackLayout>
<!-- TWO BUTTONS -->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="End"
Margin="0,1,0,2">
<Button
Margin="0,0,2,0"
ImageSource="ic_actualizar"
BackgroundColor="{Binding ColorBotonActualizar}"
HorizontalOptions="End"
VerticalOptions="Center"
HeightRequest="35"
WidthRequest="50"
Command="{Binding ActualizarSQCommand}"/>
<Button
ImageSource="ic_minus_sisquim"
BackgroundColor="{StaticResource das.color.estado_danger}"
HorizontalOptions="End"
VerticalOptions="Center"
HeightRequest="35"
WidthRequest="50"
Command="{Binding DesasociarSQCommand}"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I only needed to set Padding="0" in the frame.
HorizontalOptions and VerticalOptions where not necessary to set as #Jessie Zhang -MSFT suggested.
<Frame Padding="0">
<Button />
</Frame>
You can try to added a property Padding="0" to Frame and remove the following properties of Button.
HeightRequest="35"
WidthRequest="50"
So the code is like this:
<Frame
HorizontalOptions="End"
BackgroundColor="Green"
Grid.Column="2"
Padding="0"
Grid.Row="0">
<Button
Text="test"
BackgroundColor="Accent"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
/>
</Frame>
I am new to UWP development and working on XAML. Can someone tell me what is wrong with the following XAML where visual state is not working. when I resize the window, the values of rows and columns do not change. Also the background color of the stack panel does not change.
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="40,0,0,0">
<GridView ItemsSource="{x:Bind Ticket}">
<GridView.ItemTemplate>
<DataTemplate x:DataType="data:Ticket">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="NarrowLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="600" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="StackPanel00.Background" Value="Blue" />
<Setter Target="StackPanel00.(Grid.Column)" Value="0" />
<Setter Target="StackPanel00.(Grid.Row)" Value="0" />
<Setter Target="StackPanel01.(Grid.Column)" Value="0" />
<Setter Target="StackPanel01.(Grid.Row)" Value="1" />
<Setter Target="StackPanel10.(Grid.Row)" Value="2" />
<Setter Target="StackPanel10.(Grid.Column)" Value="0" />
<Setter Target="StackPanel11.(Grid.Column)" Value="0" />
<Setter Target="StackPanel11.(Grid.Row)" Value="3" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="WideLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1100" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="StackPanel00.(Grid.Column)" Value="0" />
<Setter Target="StackPanel00.(Grid.Row)" Value="0" />
<Setter Target="StackPanel01.(Grid.Column)" Value="1" />
<Setter Target="StackPanel01.(Grid.Row)" Value="0" />
<Setter Target="StackPanel10.(Grid.Row)" Value="1" />
<Setter Target="StackPanel10.(Grid.Column)" Value="0" />
<Setter Target="StackPanel11.(Grid.Column)" Value="1" />
<Setter Target="StackPanel11.(Grid.Row)" Value="1" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Name="StackPanel00" Grid.Row="0" Grid.Column="0" Margin="20">
<StackPanel Name="StackPanel000" Orientation="Horizontal">
<TextBlock Name="TicketLineLabel" Text="Ticket Line: " />
<TextBlock Name="TicketLineData" Text="{x:Bind Line}" Margin="10,0,0,0" />
</StackPanel>
<StackPanel Name="StackPanel001" Orientation="Horizontal" Margin="0,10,0,0" >
<TextBlock Name="TicketLocationLabel" Text="Ticket Location: " />
<TextBlock Name="TicketLocationData" Text="{x:Bind TicketLocation}" Margin="10,0,0,0" />
</StackPanel>
</StackPanel>
<StackPanel Name="StackPanel01" Grid.Row="0" Grid.Column="1" Margin="20">
<StackPanel Orientation="Horizontal" >
<TextBlock Name="StopDateFromLabel" Text="Stop Date From: " />
<TextBlock Name="StopDateFromData" Text="{x:Bind StopDateTime}" Margin="10,0,0,0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Name="InvoiceDateLabel" Text="Invoice Date: " />
<TextBlock Name="InvoiceDateData" Text="{x:Bind InvoiceDate}" Margin="10,0,0,0" />
</StackPanel>
</StackPanel>
<StackPanel Name="StackPanel10" Grid.Row="1" Grid.Column="0" Margin="20">
<StackPanel Orientation="Horizontal">
<TextBlock Name="NetBarrelsLabel" Text="Net Barrels: " RelativePanel.AlignLeftWithPanel="True" />
<TextBlock Name="NetBarrelsData" Text="{x:Bind NetBarrels}" RelativePanel.RightOf="NetBarrelsLabel" Margin="10,0,0,0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Name="WaterBarrelsLabel" Text="Water Barrels: " RelativePanel.AlignLeftWithPanel="True" />
<TextBlock Name="WaterBarrelsData" Text="{x:Bind NetBarrels}" RelativePanel.RightOf="WaterBarrelsLabel" Margin="10,0,0,0" />
</StackPanel>
</StackPanel>
<StackPanel Name="StackPanel11" Margin="20">
<StackPanel Orientation="Horizontal">
<TextBlock Name="TicketTypeLabel" Text="Ticket Type: " RelativePanel.AlignLeftWithPanel="True" />
<TextBlock Name="TicketTypeData" Text="{x:Bind TicketType}" RelativePanel.RightOf="TicketTypeLabel" Margin="10,0,0,0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Name="OriginBillingTypeLabel" Text="Origin Billing Type: " RelativePanel.AlignLeftWithPanel="True" />
<TextBlock Name="OriginBillingTypeData" Text="{x:Bind OriginBillingType}" RelativePanel.RightOf="OriginBillingTypeLabel" Margin="10,0,0,0" />
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
To make the VisualStateManager work inside a DataTemplate, we will need to place it within a Control subclass such as a UserControl like the following:
<GridView ItemsSource="{x:Bind Ticket}">
<GridView.ItemTemplate>
<DataTemplate x:DataType="data:Ticket">
<UserControl>
<Grid>
<VisualStateManager.VisualStateGroups>
...
</VisualStateManager.VisualStateGroups>
...
</Grid>
</UserControl>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
Visual states are sometimes useful for scenarios where you want to change the state of some area of UI that's not immediately a Control subclass. You can't do this directly because the control parameter of the GoToState method requires a Control subclass, which refers to the object that the VisualStateManager acts upon.
We recommend you define a custom UserControl to either be the Window.Content root or be a container for other content you want to apply states to (such as a Panel). Then you can call GoToState on your UserControl and apply states regardless of whether the rest of the content is a Control.
For more info, please see Visual states for elements that aren't controls under Remarks of VisualStateManager Class.
Hello I'm working on a xamrain forms app that has a main menu and when you click the math button it supposed to take you to the MathHome page however it crashes after you click the button on the home page
heres my code for the mathpage:
<?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:SchoolTools.Math.ViewModels;assembly=SchoolTools"
x:Class="SchoolTools.MathPage">
<ContentPage.Resources>
<ResourceDictionary>
<Style x:Key="NumberStyle" TargetType="Button">
<Setter Property="BackgroundColor" Value="White"/>
<Setter Property="TextColor" Value="Black"/>
<Setter Property="BorderRadius" Value="0"/>
<Setter Property="Font" Value="36"/>
</Style>
<Style x:Key="OperationsStyle" TargetType="Button">
<Setter Property="BackgroundColor" Value="#FFA500"/>
<Setter Property="TextColor" Value="White"/>
<Setter Property="BorderRadius" Value="0"/>
<Setter Property="Font" Value="36"/>
</Style>
<Style x:Key="BackSpaceButtonStyle" TargetType="Button">
<Setter Property="BackgroundColor" Value="Black"/>
<Setter Property="TextColor" Value="White"/>
<Setter Property="BorderRadius" Value="0"/>
<Setter Property="Font" Value="Bold,40"/>
<Setter Property="VerticalOptions" Value="CenterAndExpand"/>
<Setter Property="HorizontalOptions" Value="CenterAndExpand"/>
</Style>
<Style x:Key="CleanButtonStyle" TargetType="Button">
<Setter Property="BackgroundColor" Value="Teal"/>
<Setter Property="TextColor" Value="Black"/>
<Setter Property="BorderRadius" Value="0"/>
<Setter Property="Font" Value="36"/>
</Style>
<Style x:Key="MainLabelStyle" TargetType="Label">
<Setter Property="BackgroundColor" Value="Black"/>
<Setter Property="TextColor" Value="White"/>
<Setter Property="Font" Value="35"/>
<Setter Property="YAlign" Value="Center"/>
<Setter Property="XAlign" Value="Center"/>
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<Grid Padding="5,0" RowSpacing="1" BackgroundColor="Black" ColumnSpacing="1">
<Grid.BindingContext>
<local:MainViewModel />
</Grid.BindingContext>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"
Text="{Binding DisplayValue}" Style="{DynamicResource MainLabelStyle}" />
<Button Text="←" Grid.Row="1" Grid.Column="3" Command="{Binding BackspaceCommand}"
Style="{DynamicResource BackSpaceButtonStyle}" />
<Button Text="7" Grid.Row="3" Grid.Column="0" Command="{Binding NumberComamnd}"
CommandParameter="7" Style="{DynamicResource NumberStyle}"/>
<Button Text="8" Grid.Row="3" Grid.Column="1" Command="{Binding NumberComamnd}"
CommandParameter="8" Style="{DynamicResource NumberStyle}"/>
<Button Text="9" Grid.Row="3" Grid.Column="2" Command="{Binding NumberComamnd}"
CommandParameter="9" Style="{DynamicResource NumberStyle}"/>
<Button Text="4" Grid.Row="4" Grid.Column="0" Command="{Binding NumberComamnd}"
CommandParameter="4" Style="{DynamicResource NumberStyle}"/>
<Button Text="5" Grid.Row="4" Grid.Column="1" Command="{Binding NumberComamnd}"
CommandParameter="5" Style="{DynamicResource NumberStyle}"/>
<Button Text="6" Grid.Row="4" Grid.Column="2" Command="{Binding NumberComamnd}"
CommandParameter="6" Style="{DynamicResource NumberStyle}"/>
<Button Text="1" Grid.Row="5" Grid.Column="0" Command="{Binding NumberComamnd}"
CommandParameter="1" Style="{DynamicResource NumberStyle}"/>
<Button Text="2" Grid.Row="5" Grid.Column="1" Command="{Binding NumberComamnd}"
CommandParameter="2" Style="{DynamicResource NumberStyle}"/>
<Button Text="3" Grid.Row="5" Grid.Column="2" Command="{Binding NumberComamnd}"
CommandParameter="3" Style="{DynamicResource NumberStyle}"/>
<Button Text="0" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3"
CommandParameter="0" Style="{DynamicResource NumberStyle}" Command="{Binding NumberComamnd}" />
<Button Text="." Grid.Row="6" Grid.Column="3" Command="{Binding AddPointCommand}"
Style="{DynamicResource OperationsStyle}"/>
<Button Text="/" Grid.Row="2" Grid.Column="2" Command="{Binding OperatorCommand}"
CommandParameter="/" Style="{DynamicResource OperationsStyle}"/>
<Button Text="x" Grid.Row="2" Grid.Column="3" Command="{Binding OperatorCommand}"
CommandParameter="x" Style="{DynamicResource OperationsStyle}" Font="25"/>
<Button Text="-" Grid.Row="3" Grid.Column="3" Command="{Binding OperatorCommand}"
CommandParameter="-" Style="{DynamicResource OperationsStyle}"/>
<Button Text="+" Grid.Row="4" Grid.Column="3" Command="{Binding OperatorCommand}"
CommandParameter="+" Style="{DynamicResource OperationsStyle}"/>
<Button Text="√" Grid.Row="2" Grid.Column="1" Command="{Binding OperatorCommand}"
CommandParameter="√" Style="{DynamicResource OperationsStyle}"/>
<Button Text="=" Grid.Row="5" Grid.Column="3" Command="{Binding CalculationCommand}"
Style="{DynamicResource OperationsStyle}"/>
<Button Text="C" Grid.Row="2" Grid.Column="0" Command="{Binding CleanCommand}"
Style="{DynamicResource CleanButtonStyle}"/>
</Grid>
</ContentPage>
I think my xmlns:local is messed up the class the xaml references is MainViewModel witch is in a folder in the project called Math and then sub folder within math called ViewModels
Any ideas on how to fix this issue?
The problem does not seem to be in your local namespace declaration but seems to be in you using properties which are marked as obsolete.
Have a look at this piece of your XAML, to which your error messages refer.
<Style x:Key="MainLabelStyle" TargetType="Label">
<Setter Property="BackgroundColor" Value="Black"/>
<Setter Property="TextColor" Value="White"/>
<Setter Property="Font" Value="35"/>
<Setter Property="YAlign" Value="Center"/>
<Setter Property="XAlign" Value="Center"/>
</Style>
If we lookup the YAlign and XAlign in the Xamarin Forms documentation, you'll see they are marked as obsolete. You should now use VerticalTextAlignment and HorizontalTextAlignment respectively.