Search bar glass in MAC is not working

Dani_S 3,126 Reputation points
2024-06-05T07:13:28.81+00:00

Hi,

Search bar glass in MAC is not working.

 <HorizontalStackLayout Grid.Row="1" Grid.Column="0" Margin="10,10,0,5" HorizontalOptions="Start" WidthRequest="285">


 <SearchBar  x:Name="searchBar" WidthRequest="250" SearchCommand="{Binding PerformSearchCommand}" 

         Placeholder="Search in log file..."   Text="{Binding SearchText, Mode=TwoWay}"/>

 <ImageButton x:Name="cancelCommand" Source="cancel.png" WidthRequest="25" HeightRequest="25"  Command="{Binding CancelSearchCommand}" 

          ToolTipProperties.Text="Cancel serach"/>
 </HorizontalStackLayout>

LogsViewModel

public ICommand PerformSearchCommand { get; private set; }
 public LogsViewModel()

 {


 try

 {

      PerformSearchCommand = new Command(PerformSearchCommandExcute);

  }

 catch (Exception ex)

 {

     _logger.Error("LogsViewModel", ex);

 }
 }

   private async void PerformSearchCommandExcute(object searchTextObj)

   {


   if (string.IsNullOrEmpty(SearchText))

   {

       await LoadDataAsync(true, SearchText);

   }

   else

   {

       await LoadDataAsync(false, SearchText);

   }
  }


      public async Task LoadDataAsync(bool fullSearch, string searchString)

  {

      try

      {

          BusyIndicatorIsBusy = true;

          await System.Threading.Tasks.Task.Delay(500);

          var clientFilePath = @"C:\GssdDesktopClient\Logs\GssdDesktopClient.log";

          if (!File.Exists(clientFilePath))

          {

              var message = "Log file doesn't exist";

              IsOpenPopup = true;

              ErrorMessage = message;

              _logger.Error(message);

              BusyIndicatorIsBusy = false;

              return;

          }

          var results = EncriptFile(clientFilePath, fullSearch, searchString);

          LogText = results;

          this.ScrollAction();// call the action

          BusyIndicatorIsBusy = false;

      }

      catch (Exception ex)

      {

          var message = "There was a problem to load the log file.";

          IsOpenPopup = true;

          ErrorMessage = message;

          _logger.Error("LoadDataAsync",ex);

          BusyIndicatorIsBusy = false;

      }

  }

  private string EncriptFile(string fileName, bool fullSearch, string searchString)

  {

      StringBuilder sb = new StringBuilder();

      var lines = File.ReadAllLines(fileName);

      int i = 0;

      Stack<string> reverseStackStrings = new Stack<string>();

      foreach (var line in lines.Reverse())

      {

          if (i > 500)

          {

              break;

          }

          reverseStackStrings.Push(line);

          i++;

      }

      foreach (string line in reverseStackStrings)

      {

          //if (i > 500)

          //{

          //    break;

          //}

          string[] spearator = { "GSSD" };

          var splitedLine = line.Split(spearator, StringSplitOptions.RemoveEmptyEntries);

          if (splitedLine != null && splitedLine.Length > 0)

          {

              string post = string.Empty;

              string pre = splitedLine[0];

              if (splitedLine.Length > 1)

              {

                  post = splitedLine[1];

              }

              if (!string.IsNullOrEmpty(pre) && !string.IsNullOrEmpty(post))

              {

                  var encriptedPost = AesHelper.Decrypt(post);

                  var concatValue = $"{pre}{encriptedPost}";

                  if (fullSearch)

                  { 

                      sb.AppendLine(concatValue);

                  }

                  else

                  { 

                      if(concatValue.ToUpper().Contains(searchString.ToUpper()))

                      {

                          sb.AppendLine(concatValue);

                      }

                  }

              }

              else

              {

                  if (fullSearch)

                  {

                      sb.AppendLine(line);

                  }

                  else

                  {

                      if(line.ToUpper().Contains(searchString.ToUpper())) 

                      { 

                          sb.AppendLine(line);

                      }

                  }

              }

          }

       }

      return sb.ToString();

  }


.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,093 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 28,071 Reputation points Microsoft Vendor
    2024-06-07T08:35:02.9866667+00:00

    Hello,

    MAUI search bar is rendered by UISearchBar on iOS/Maccatalyst platforms. This glass is an icon, and it cannot be clicked by default. Please see Apple's description: UISearchBarIconSearch | Apple Developer Documentation and the searchbar section in iOS Human Interface Guidelines

    If you want to trigger the command to search, you can press the return/enter key on your Mac's Keyboard.

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 59,546 Reputation points
    2024-06-06T18:23:30.6066667+00:00