Rad button not disabled

1 Answer 222 Views
Button
Daniel
Top achievements
Rank 1
Silver
Bronze
Daniel asked on 14 Mar 2022, 02:31 PM | edited on 14 Mar 2022, 02:33 PM

Hi,

Rad button not disabled in this scenario,

  <telerik:RadButton  AutomationId="button" Text="Search" HorizontalOptions="CenterAndExpand" VerticalOptions="Center"  BackgroundColor="#1ABB9C" Margin="5"  Command="{Binding OnDashBoardCommand}"/>
    public ICommand OnDashBoardCommand { get; private set; }
  private void InitCommands()
        {
            OnDashBoardCommand = new Command(
               execute: () =>
               {
                   .........
               },
               canExecute: () =>
               {
                   if (!(FromDate.HasValue && ToDate.HasValue))
                   {
                       return false;
                   }
                   return FromDate.Value <= ToDate.Value;
               });
        }


Lance | Manager Technical Support
Telerik team
commented on 16 Mar 2022, 05:01 PM

I have seen your DashboardViewModel class in another forum post and it doesn't implement INotifyPropertyChanged. This means then the Button is never getting that command because the data binding is never updated (it's always null).

Make sure you are instantiating the commands in the view model's constructor OR use INotifyPropertyChanged.

public class DashboardViewModel
{
    public DashboardViewModel()
    {
        // You must call this here, OR use INotifyPropertyChanged
        InitiCommands();
    }
}

 

Lance | Manager Technical Support
Telerik team
commented on 16 Mar 2022, 06:39 PM

Hi Daniel, I found an issue with CanExecute in MAUI. This is unrelated to Telerik UI for MAUI, and is something Microsoft has to fix (you can always verify such things by trying it with a normal Button instead of a RadButton).

Unfortunately, there's nothing we can do about it until Microsoft fixes it. You can open an Issue here Issues · dotnet/maui (github.com)

In the meantime, you can always disable a Button/Radbutton by using the IsEnabled property:

Lance | Manager Technical Support
Telerik team
commented on 16 Mar 2022, 07:28 PM

One more final tip I should share. do not 100% rely on the color of a button as being the disabled state. Make sure you actually try to click the button to confirm whether it is enabled or disabled.

This is because the MAUI styling theme Microsoft uses on certain platforms might not be that obvious. For example, on android the only difference between an enabled or disabled button is a light shadow.

What you can also do is add a D

<Button IsEnabled="{Binding IsMyButtonEnabled}"
        Text="I'm a button"
        BackgroundColor="Blue">
 <Button.Triggers>
 <DataTrigger TargetType="Button"
                     Binding="{Binding IsMyButtonEnabled}"
                     Value="True">
  <Setter Property="BackgroundColor"Value="Red" />
 </DataTrigger>
 </Button.Triggers>
</Button>
ataTrigger than changes the BackgroundColor based on that value:

 

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 17 Mar 2022, 01:53 PM

Microsoft test the bug and say it OK in there side.

https://github.com/dotnet/maui/issues/5364#issuecomment-1070943997

 

 

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 17 Mar 2022, 04:00 PM

Hi Daniel,

As I mentioned in the GitHub conversation, this is working for me and Gerald. Both RadButton and Button are disabled, I have attached a runnable project you can use to confirm.

I cannot identify any bug in terms of initial CanExecute value return, please investigate other pathways in the custom business logic (make sure your code is returning false when it first loads) or incorrect binding configurations (i.e. no OnPropertyChanged notifications, etc.)

For example, to eliminate any custom business logic issues, do this:

Demo

When you run my demo, please pay close attention to the fact that when you click the checkbox, the buttons do not become re-enabled... this is expected behavior and is important to keep in mind.

If you are actually looking for a dynamic implementation that enables/disables the buttons, you will need to use a different option than CanExecute. For example, binding a bool to IsEnabled as seen in my earlier comment.

 

Note: The demo uses UI for MAUI 0.5.0, which requires preview13. If you have updated your development environment to preview14, you will need to wait until we release Telerik UI for MAUI 0.6.0 (tomorrow or Monday)

Regards,
Lance | Manager Technical Support
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 17 Mar 2022, 04:42 PM

i didnt update my enviorement.

What i need to do to move preview 14 to use your new telerik ui for maui 0.6.0

Lance | Manager Technical Support
Telerik team
commented on 17 Mar 2022, 05:09 PM

Did you try and run my demo? It is configured for your environment (.NET MAUI preview13) and will work as-is with Telerik UI for MAUI 0.5.0.

My comment about preview14 was only to warn you that if you already updated to preview14, you will need to wait until we release Telerik UI for MAUI 0.6.0.

However, you should be aware that after we release 0.6.0, you will need to also update .NET MAUI. That is done by updating VS 2022 Preview and running the dotnet workload commands (dotnet workload install maui --ignore-failed-sources)

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 17 Mar 2022, 05:21 PM

1.how i update the vs 2022 preview and where i run this command.

I know to install and uninstall.

Can you give screenshoots ?

Lance | Manager Technical Support
Telerik team
commented on 17 Mar 2022, 05:45 PM

Progress Telerik and Microsoft are different companies. This is the Telerik forums you're typing into right now, we do not build Visual Studio or .NET MAUI, those things are built by Microsoft (the .NET and Visual Studio teams).

If you need help with using Visual Studio features or .NET MAUI features, you can use their forums instead Microsoft supported products on Q&A | Microsoft Docs.

If you want a quicker answer, I strongly recommend just Googling the following terms:

Please Read Carefully

In the hopes that I can help prevent you from breaking your project... do not update to preview14 right now. Your development machine has preview13 installed right now, this works with our UI for MAUI 0.5.0.

If you update before we release Telerik UI for MAUI v0.6.0, your project will be broken. After we release 0.6.0, you can safely update your development machine to preview14.

Professional Services

If you would like hand-on help, and have someone teach you all these things, you can contact our Outsourcing team. They will help set you up with a one-on-one trainer, where you can learn the new things you need to to move forward in your development efforts and filling the missing gaps that you need to fill.

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 17 Mar 2022, 05:55 PM

i didnt make any update yet.
Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 18 Mar 2022, 06:48 PM

i didnt make any chance yet.

waiting to know when you moved.

From this link it recommend to uninstall vs 2022 preview 17.2 and install a new one.

Open new project and copy all files from previous

Project to new one.

Announcing .NET MAUI Preview 14 - .NET Blog (microsoft.com)

 

 


 

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 20 Mar 2022, 09:09 AM

Hi,

I tried your demo, and is not work well in my side.

I attached demo.

I used this code:


  <telerik:RadButton  AutomationId="button" HorizontalOptions="CenterAndExpand" VerticalOptions="Center" BackgroundColor="White" BackgroundImage="refreshdashboard.png" Command="{Binding SearchCommand}" WidthRequest="20" HeightRequest="20" BorderThickness="0"
                                    IsEnabled="{Binding IsEnabledSearchCommand , Mode=TwoWay}">
                    <telerik:RadButton.Triggers>
                        <DataTrigger TargetType="telerik:RadButton"
                     Binding="{Binding IsEnabledSearchCommand , Mode=TwoWay}"
                     Value="False">
                            <Setter Property="BackgroundImage" Value="clear.png" />
                        </DataTrigger>
                        <DataTrigger TargetType="telerik:RadButton"
                     Binding="{Binding IsEnabledSearchCommand , Mode=TwoWay}"
                     Value="true">
                            <Setter Property="BackgroundImage" Value="refreshdashboard.png" />
                        </DataTrigger>
                    </telerik:RadButton.Triggers>
                </telerik:RadButton>
  private void InitCommands()
        {
            SearchCommand = new Command(
               execute: () =>
               {
                   
                   ((Command)SearchCommand).ChangeCanExecute();


               },
               canExecute: () =>
               {
                   if (!(FromDate.HasValue && ToDate.HasValue))
                   {
                       IsEnabledSearchCommand = false;
                       return false; 
                   }
                   if(FromDate.Value <= ToDate.Value)
                   {
                       IsEnabledSearchCommand = true;
                       return true;
                   }
                   else
                   {
                       IsEnabledSearchCommand = false;
                       return IsEnabledSearchCommand ;
                   }
               });

 

 

 

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 27 Mar 2022, 11:43 AM

I took another copy of my project.

1. I uninstall vs 20202 preview 17.2  Preview 1.

2.Install Version 17.2.0 Preview 2.1

3. Running the dotnet workload commands (dotnet workload install maui --ignore-failed-sources)

4.Build project passed succeccfully.

5.But pages stop working... pages with charts and more controls stop working...

What do I miss ?

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 27 Mar 2022, 12:45 PM | edited

This code also stop working.

 
    private async Task<string> GetConfigurations()
    {
        await using var stream = await FileSystem.OpenAppPackageFileAsync("Configuration.xml");
        using var reader = new StreamReader(stream);
        var configurationXml = await reader.ReadToEndAsync();

        return configurationXml;

    }
Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 27 Mar 2022, 02:07 PM | edited

<The UI become RTL and expand button not works, when I press on one of the view i got this exception.

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 27 Mar 2022, 02:08 PM

The message is :Specified argument was out of the range of valid values.

This code work properly before converting it today morning.

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 28 Mar 2022, 06:02 AM

My current vs
Lance | Manager Technical Support
Telerik team
commented on 28 Mar 2022, 01:57 PM | edited

Hi Daniel, this is just a fact of life when building projects with previews. You should 100% expect breaking changes and put in all the work that it takes to find where it stopped working.

I don't have an answer for you about why the code you wrote on top of preview13 is throwing that error on preview14. I am able to use RadButton on preview14 without error.

Moving Forward

My recommendation would be to replace RadButton with Button and continue testing..

  1. Is is still broken with Button? -> The problem is in MAUI itself
  2. Is it only broken with RadButton, but works with Button?  -> The problem is with a Telerik feature

If you find that #2 is true, please prepare a separate test project that replicates the exception (do not just send code snippets or screenshots, they will not be tested as the environment and project setup is critical information).

 

 

Tags
Button
Asked by
Daniel
Top achievements
Rank 1
Silver
Bronze
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or