Forum Libraries, Components, and Plugins
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How can I change style CanExecute?

MODERN122MODERN122 Member ✭✭

I use framework Prism. I have two buttons they uses like switch, and i want to style them.
@BrianLagunas How can I change the styling of Button CanExecute, the same background and textColor?

Button Text="{Binding NumberOpen, StringFormat='Текущие {0:F0}'}" Command="{Binding SwitchDeliveryTypeCommand}" CommandParameter="false"/> <Button Text="{Binding NumberClose, StringFormat='Завершенные {0:F0}'}" Command="{Binding SwitchDeliveryTypeCommand}" CommandParameter="true"/>

Best Answer

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    If you want to style button, you can refer to the offcial document Styling Xamarin.Forms Apps using XAML Styles

    There are different type of Styles, for example Explicit Styles, Implicit Styles , Global Styles and so on.

    Take explicit style for example:

      <Style x:Key="buttonStyle" TargetType="Button">
                <Setter Property="HorizontalOptions" Value="Center" />
                <Setter Property="VerticalOptions" Value="CenterAndExpand" />
                <Setter Property="FontSize" Value="Large" />
                <Setter Property="TextColor" Value="Blue" />
                <Setter Property="BackgroundColor" Value="Yellow"/>
            </Style>
    

    And use like this:

     <Button Text="test "  Style="{StaticResource buttonStyle}"/>
    
  • MODERN122MODERN122 Member ✭✭
    > @jezh said:
    > If you want to style button, you can refer to the offcial document Styling Xamarin.Forms Apps using XAML Styles
    >
    > There are different type of Styles, for example Explicit Styles, Implicit Styles , Global Styles and so on.
    >
    > Take explicit style for example:
    >
    > <Style x:Key="buttonStyle" TargetType="Button"> <Setter Property="HorizontalOptions" Value="Center" /> <Setter Property="VerticalOptions" Value="CenterAndExpand" /> <Setter Property="FontSize" Value="Large" /> <Setter Property="TextColor" Value="Blue" /> <Setter Property="BackgroundColor" Value="Yellow"/> </Style>
    >
    > And use like this:
    >
    > <Button Text="test " Style="{StaticResource buttonStyle}"/>

    I use prism.forms and delegateCommand from their, its contains CanCommand, if return true, i can click, false - no.
    I want this override, cause default, if i cant click textColor just gray, i need to black
  • jezhjezh Member, Xamarin Team Xamurai

    Hi @MODERN122, have you resolved your question?

  • MODERN122MODERN122 Member ✭✭

    @jezh said:
    Hi @MODERN122, have you resolved your question?

    Thank you for trying to help me, but the problem with using Xamarin CanExecutedMethod from prism is that in runtime prism override isEnabled for TextColor, and it doesn't make sense in styles, for those who don't use Prism, it can be useful, but not in my case, I used a bundle of Two converters where I pass Boolean values, this is not the best use of them, but I couldn't do it any other way.

    <StackLayout Grid.Row="1" Orientation="Horizontal" HorizontalOptions="CenterAndExpand"> <Button Text="{Binding NumberOpen, StringFormat='Текущие {0:F0}'}" Command="{Binding SwitchDeliveryTypeCommand}" CommandParameter="false" BackgroundColor="{Binding FlagSwitch, Converter={StaticResource booleanToBackgroundColorConverter}, ConverterParameter='false'}" TextColor="{Binding FlagSwitch, Converter={StaticResource booleanToBackgroundColorConverter}, ConverterParameter='true'}"/> <Button Text="{Binding NumberClose, StringFormat='Завершенные {0:F0}'}" Command="{Binding SwitchDeliveryTypeCommand}" CommandParameter="true" BackgroundColor="{Binding FlagSwitch, Converter={StaticResource booleanToBackgroundColorConverter}, ConverterParameter='true'}" TextColor="{Binding FlagSwitch, Converter={StaticResource booleanToBackgroundColorConverter}, ConverterParameter='false'}"/> </StackLayout>

Sign In or Register to comment.