Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public override string ToString()
new GalleryPageFactory(() => new RadioButtonCoreGalleryPage(), "RadioButton Gallery"),
new GalleryPageFactory(() => new ScrollViewCoreGalleryPage(), "ScrollView Gallery"),
new GalleryPageFactory(() => new ShadowFeaturePage(), "Shadow Feature Matrix"),
new GalleryPageFactory(() => new SearchBarControlPage(), "Search Bar Feature Matrix"),
new GalleryPageFactory(() => new SearchBarCoreGalleryPage(), "Search Bar Gallery"),
new GalleryPageFactory(() => new SliderCoreGalleryPage(), "Slider Gallery"),
new GalleryPageFactory(() => new StepperControlPage(), "Stepper Feature Matrix"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.SearchBarControlMainPage"
x:DataType="local:SearchBarViewModel"
Title="ControlPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Options"
Clicked="NavigateToOptionsPage_Clicked"
AutomationId="Options"/>
</ContentPage.ToolbarItems>

<Grid x:Name="MainGrid"
RowDefinitions="*,Auto, Auto, Auto, Auto"
ColumnDefinitions="0.5*, 0.5*">
<Grid x:Name="SearchBarGrid"
Grid.Row="0"
Grid.ColumnSpan="2"
VerticalOptions="Center">
<SearchBar x:Name="searchBar"
AutomationId="SearchBar"
CancelButtonColor="{Binding CancelButtonColor}"
CharacterSpacing="{Binding CharacterSpacing}"
CursorPosition="{Binding CursorPosition}"
FlowDirection="{Binding FlowDirection}"
FontAttributes="{Binding FontAttributes}"
FontAutoScalingEnabled="{Binding FontAutoScalingEnabled}"
FontFamily="{Binding FontFamily}"
FontSize="{Binding FontSize}"
HorizontalTextAlignment="{Binding HorizontalTextAlignment}"
IsEnabled="{Binding IsEnabled}"
IsVisible="{Binding IsVisible}"
Shadow="{Binding Shadow}"
IsReadOnly="{Binding IsReadOnly}"
IsSpellCheckEnabled="{Binding IsSpellCheckEnabled}"
IsTextPredictionEnabled="{Binding IsTextPredictionEnabled}"
Keyboard="{Binding Keyboard}"
MaxLength="{Binding MaxLength}"
Placeholder="{Binding Placeholder}"
PlaceholderColor="{Binding PlaceholderColor}"
SearchButtonPressed="OnSearchButtonPressed"
SearchCommand="{Binding SearchCommand}"
SearchCommandParameter="{Binding Text, x:DataType='SearchBar', Source={x:Reference searchBar}}"
SelectionLength="{Binding SelectionLength}"
Text="{Binding Text}"
TextColor="{Binding TextColor}"
TextChanged="OnTextChanged"
TextTransform="{Binding TextTransform}"
VerticalTextAlignment="{Binding VerticalTextAlignment}"/>
</Grid>

<Label Grid.Row="1"
Grid.Column="0"
HorizontalOptions="Center"
Text="Search Button Pressed: "/>
<Label Grid.Row="1"
Grid.Column="1"
x:Name="SearchButtonPressedLabel"
AutomationId="SearchButtonPressedLabel"
HorizontalOptions="Center"
Text="No"/>

<Label Grid.Row="2"
Grid.Column="0"
HorizontalOptions="Center"
Text="New Text: "/>
<Label Grid.Row="2"
Grid.Column="1"
x:Name="NewTextChangedLabel"
HorizontalOptions="Center"
AutomationId="NewTextChangedLabel"/>

<Label Grid.Row="3"
Grid.Column="0"
HorizontalOptions="Center"
Margin="0,0,0,100"
Text="Old Text: "/>
<Label Grid.Row="3"
Grid.Column="1"
x:Name="OldTextChangedLabel"
HorizontalOptions="Center"
Margin="0,0,0,100"
AutomationId="OldTextChangedLabel"/>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
namespace Maui.Controls.Sample;

public class SearchBarControlPage : NavigationPage
{
private SearchBarViewModel _viewModel;
public SearchBarControlPage()
{
_viewModel = new SearchBarViewModel();
PushAsync(new SearchBarControlMainPage(_viewModel));
}
}
public partial class SearchBarControlMainPage : ContentPage
{
private SearchBarViewModel _viewModel;

public SearchBarControlMainPage(SearchBarViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
}

private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
{
BindingContext = _viewModel = new SearchBarViewModel();
ReInitializeSearchBar();
await Navigation.PushAsync(new SearchBarOptionsPage(_viewModel));
}

private void ReInitializeSearchBar()
{
SearchBarGrid.Children.Clear();

var searchBar = new SearchBar
{
AutomationId = "SearchBar",
};
searchBar.SetBinding(SearchBar.CancelButtonColorProperty, nameof(SearchBarViewModel.CancelButtonColor));
searchBar.SetBinding(SearchBar.CharacterSpacingProperty, nameof(SearchBarViewModel.CharacterSpacing));
searchBar.SetBinding(SearchBar.CursorPositionProperty, nameof(SearchBarViewModel.CursorPosition));
searchBar.SetBinding(SearchBar.FlowDirectionProperty, nameof(SearchBarViewModel.FlowDirection));
searchBar.SetBinding(SearchBar.FontAttributesProperty, nameof(SearchBarViewModel.FontAttributes));
searchBar.SetBinding(SearchBar.FontAutoScalingEnabledProperty, nameof(SearchBarViewModel.FontAutoScalingEnabled));
searchBar.SetBinding(SearchBar.FontFamilyProperty, nameof(SearchBarViewModel.FontFamily));
searchBar.SetBinding(SearchBar.FontSizeProperty, nameof(SearchBarViewModel.FontSize));
searchBar.SetBinding(SearchBar.HorizontalTextAlignmentProperty, nameof(SearchBarViewModel.HorizontalTextAlignment));
searchBar.SetBinding(SearchBar.IsEnabledProperty, nameof(SearchBarViewModel.IsEnabled));
searchBar.SetBinding(SearchBar.IsVisibleProperty, nameof(SearchBarViewModel.IsVisible));
searchBar.SetBinding(SearchBar.ShadowProperty, nameof(SearchBarViewModel.Shadow));
searchBar.SetBinding(SearchBar.IsReadOnlyProperty, nameof(SearchBarViewModel.IsReadOnly));
searchBar.SetBinding(SearchBar.IsSpellCheckEnabledProperty, nameof(SearchBarViewModel.IsSpellCheckEnabled));
searchBar.SetBinding(SearchBar.IsTextPredictionEnabledProperty, nameof(SearchBarViewModel.IsTextPredictionEnabled));
searchBar.SetBinding(SearchBar.KeyboardProperty, nameof(SearchBarViewModel.Keyboard));
searchBar.SetBinding(SearchBar.MaxLengthProperty, nameof(SearchBarViewModel.MaxLength));
searchBar.SetBinding(SearchBar.PlaceholderProperty, nameof(SearchBarViewModel.Placeholder));
searchBar.SetBinding(SearchBar.PlaceholderColorProperty, nameof(SearchBarViewModel.PlaceholderColor));
searchBar.SetBinding(SearchBar.SelectionLengthProperty, nameof(SearchBarViewModel.SelectionLength));
searchBar.SetBinding(SearchBar.TextProperty, nameof(SearchBarViewModel.Text));
searchBar.SetBinding(SearchBar.TextColorProperty, nameof(SearchBarViewModel.TextColor));
searchBar.SetBinding(SearchBar.TextTransformProperty, nameof(SearchBarViewModel.TextTransform));
searchBar.SetBinding(SearchBar.VerticalTextAlignmentProperty, nameof(SearchBarViewModel.VerticalTextAlignment));
searchBar.SetBinding(SearchBar.SearchCommandProperty, nameof(SearchBarViewModel.SearchCommand));
searchBar.SetBinding(SearchBar.SearchCommandParameterProperty, nameof(SearchBarViewModel.Text));

searchBar.SearchButtonPressed += OnSearchButtonPressed;
searchBar.TextChanged += OnTextChanged;

NewTextChangedLabel.Text = string.Empty;
OldTextChangedLabel.Text = string.Empty;
SearchButtonPressedLabel.Text = "No";

SearchBarGrid.Children.Add(searchBar);
}

private void OnSearchButtonPressed(object sender, EventArgs e)
{
var searchBar = sender as SearchBar;
if (searchBar != null && !string.IsNullOrEmpty(searchBar.Text))
{
SearchButtonPressedLabel.Text = "Yes";
}
}

private void OnTextChanged(object sender, TextChangedEventArgs e)
{
if (!string.IsNullOrEmpty(e.NewTextValue))
{
NewTextChangedLabel.Text = e.NewTextValue;
OldTextChangedLabel.Text = e.OldTextValue;
}
}
}
Loading
Loading