Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 印德里,看一看。。thanksI补充了另一个问题,在我看来,这是正确的方法,我没有测试它,所以你可能需要修复或调整它,我希望它能让你继续。我使用了这个答案,仍然不起作用。。。没有错误,我在转换器中插入断点,并且正在调用断点。。但是,我不知道为什么它不起作用_C#_.net_Xamarin_Xamarin.forms - Fatal编程技术网

C# 印德里,看一看。。thanksI补充了另一个问题,在我看来,这是正确的方法,我没有测试它,所以你可能需要修复或调整它,我希望它能让你继续。我使用了这个答案,仍然不起作用。。。没有错误,我在转换器中插入断点,并且正在调用断点。。但是,我不知道为什么它不起作用

C# 印德里,看一看。。thanksI补充了另一个问题,在我看来,这是正确的方法,我没有测试它,所以你可能需要修复或调整它,我希望它能让你继续。我使用了这个答案,仍然不起作用。。。没有错误,我在转换器中插入断点,并且正在调用断点。。但是,我不知道为什么它不起作用,c#,.net,xamarin,xamarin.forms,C#,.net,Xamarin,Xamarin.forms,印德里,看一看。。thanksI补充了另一个问题,在我看来,这是正确的方法,我没有测试它,所以你可能需要修复或调整它,我希望它能让你继续。我使用了这个答案,仍然不起作用。。。没有错误,我在转换器中插入断点,并且正在调用断点。。但是,我不知道为什么它不起作用;)。。我添加了上面的代码,看一看,可能我遗漏了什么..启动应用程序时按钮是否已启用?是的,它已启用。。我可以导航到另一个页面,而无需从picker中选择任何项目。我编辑了我的答案,请注意,在视图模型中创建命令时,我添加了(x)=>false作


印德里,看一看。。thanksI补充了另一个问题,在我看来,这是正确的方法,我没有测试它,所以你可能需要修复或调整它,我希望它能让你继续。我使用了这个答案,仍然不起作用。。。没有错误,我在转换器中插入断点,并且正在调用断点。。但是,我不知道为什么它不起作用;)。。我添加了上面的代码,看一看,可能我遗漏了什么..启动应用程序时按钮是否已启用?是的,它已启用。。我可以导航到另一个页面,而无需从picker中选择任何项目。我编辑了我的答案,请注意,在视图模型中创建命令时,我添加了(x)=>false作为第二个参数,这将解决问题。
<Picker x:Name="picker_provider" 
        Title="Select a Provider">
        <Picker.ItemsSource>
            <x:Array Type="{x:Type x:String}">
                <x:String>Provider 1</x:String>
                <x:String>Provider 2</x:String>
            </x:Array>
        </Picker.ItemsSource>
</Picker>

<Button
    Text="Next"
    Command="{Binding NextPageCommand}"/>
public async Task NextPage(RegisterViewModel nextpage) => await NavigationService.NavigateToAsync(nextpage, null, NavigationType.Modal);

#region Bindable Command
public ICommand NextPageCommand => new Command<RegisterViewModel>(async (nextpage) =>
    {
        await NextPage(nextpage);
    });
#endregion
public bool IsNextButtonEnabled => SelectedItem!=null;
public string SelectedItem 
{
    get=>_selectedItem;
    set { _selectedItem = value; OnPropertyChanged("SelectedItem");}
}
private string _selectedItem;
<Picker x:Name="picker_provider" 
    Title="Select a Provider" 
    SelectedItem="{Binding SelectedItem}>
    <Picker.ItemsSource>
        <x:Array Type="{x:Type x:String}">
            <x:String>Provider 1</x:String>
            <x:String>Provider 2</x:String>
        </x:Array>
    </Picker.ItemsSource>
public ICommand NextPageCommand => new Command<RegisterViewModel>(async (nextpage) =>
{
    if(_selectedItem == "Provider 1")  await ThisPage();
    else                               await OtherPage();
});
<ContentPage.Resources>
    <ResourceDictionary>
        <local:MultiTriggerConverter x:Key="dataHasBeenEntered" />
    </ResourceDictionary>

</ContentPage.Resources>

<StackLayout>
    <Picker x:Name="picker_provider" 
            Title="Select a Provider" SelectedItem="{Binding xxx}">
        <Picker.ItemsSource>
            <x:Array Type="{x:Type x:String}">
                <x:String>Provider 1</x:String>
                <x:String>Provider 2</x:String>
            </x:Array>
        </Picker.ItemsSource>
    </Picker>

    <Button Text="Next" IsEnabled="False" Command="{}">
        <Button.Triggers>
            <DataTrigger 
                TargetType="Button"
                Binding="{Binding Source={x:Reference picker_provider}, Path = SelectedIndex ,
                Converter={StaticResource dataHasBeenEntered}}" Value="true">
                <Setter Property="IsEnabled" Value="True" />
            </DataTrigger>
        </Button.Triggers>
    </Button>
</StackLayout>


public class MultiTriggerConverter : IValueConverter
{
    public object Convert(object value, Type targetType,
        object parameter, CultureInfo culture)
    {
        if ((int)value >= 0) // length > 0 ?
            return true;            // some data has been entered
        else
            return false;            // input is empty
    }

    public object ConvertBack(object value, Type targetType,
        object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}
public ICommand NextPageCommand => new Command<RegisterViewModel>(async (nextpage) =>
{

     // here you could get the value of `Picker.SelectedItem`. 
     
});
private bool _canNavigate;
public bool CanNavigate
{
    get { return _canNavigate; }
    set { this.RaiseAndSetIfChanged(ref _canNavigate, value) }
}
<Button
Text="Next"
IsEnabled="{Binding CanNavigate}"
Command="{Binding NextPageCommand}"/>
private string _selectedItem;
public string SelectedItem {
  get { return _selectedItem; }
  set 
  { 
      if (!string.IsNullOrWhiteSpace(value)) 
      {
          this.RaiseAndSetIfChanged(ref _selectedItem, value) }
      }
  }
}
<Picker x:Name="picker_provider" 
        Title="Select a Provider" SelectedItem="{Binding SelectedItem}">
    <Picker.ItemsSource>
        <x:Array Type="{x:Type x:String}">
            <x:String>Provider 1</x:String>
            <x:String>Provider 2</x:String>
        </x:Array>
    </Picker.ItemsSource>
</Picker>
namespace Osma.Mobile.App.Converters
{
    public class StringNullOrEmptyValueBoolConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string str && !string.IsNullOrEmpty(str))
            {
                // String is not null or empty
                return false;
            }
            
            // String is null or empty
            return true;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
public class ProviderViewModel : ABaseViewModel
{
    public ProviderViewModel(
        IUserDialogs userDialogs,
        INavigationService navigationService
        ) : base(
            nameof(ProviderViewModel),
            userDialogs,
            navigationService)
    {
    }

    public override async Task InitializeAsync(object navigationData)
    {
        await base.InitializeAsync(navigationData);
    }

   private string _selectedProvider;
   public string SelectedProvider {
       get { return _selectedProvider; }
       set 
       { 
            this.RaiseAndSetIfChanged(ref _selectedProvider, value) }
       }
  }

   private string _selectedCountry;
   public string SelectedCountry {
       get { return _selectedCountry; }
       set 
       { 
           this.RaiseAndSetIfChanged(ref _selectedCountry, value) }
       }
  }

    public async Task RegistrationPage(RegisterViewModel registration) => await NavigationService.NavigateToAsync(registration, null, NavigationType.Modal);

    public ICommand RegistrationPageCommand => new Command<RegisterViewModel>(async (registration) =>
    {
        await RegistrationPage(registration);
    }, (x) => false);
}
<?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:converters="clr-namespace:Osma.Mobile.App.Converters"
             x:Class="Osma.Mobile.App.Views.ProviderPage"
             NavigationPage.HasNavigationBar="False"
             BackgroundColor="#004B86">

   <ContentPage.Resources>
    <ResourceDictionary>
        <converters:StringNullOrEmptyValueBoolConverter x:Key="stringNullOrEmptyValueBoolConverter" />
    </ResourceDictionary>
   </ContentPage.Resources>


    <ContentPage.Content>
        <StackLayout
            Spacing="30">

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="70" />
                    <RowDefinition Height="70" />
                </Grid.RowDefinitions>
                
                <Grid Grid.Row="0">
                    <Picker 
                        x:Name="picker_country" 
                        Title="Select a Country" 
                        TextColor="Silver" 
                        TitleColor="Silver" 
                        HorizontalOptions="Start" 
                        WidthRequest = "200" 
                        VerticalOptions="Start" 
                        Margin="130,0,0,0"
                        SelectedItem="{Binding SelectedCountry}">
                        <Picker.ItemsSource>
                            <x:Array Type="{x:Type x:String}">
                                <x:String>Sweden</x:String>
                            </x:Array>
                        </Picker.ItemsSource>
                    </Picker>
                </Grid>

                <Grid Grid.Row="1">
                    <Picker 
                        x:Name="picker_provider" 
                        Title="Select a Provider" 
                        TextColor="Silver" 
                        TitleColor="Silver" 
                        HorizontalOptions="Start" 
                        WidthRequest = "200" 
                        VerticalOptions="Start" 
                        Margin="130,0,0,0"
                        SelectedItem="{Binding SelectedProvider}">
                        <Picker.ItemsSource>
                            <x:Array Type="{x:Type x:String}">
                                <x:String>Provider 1</x:String>
                            </x:Array>
                        </Picker.ItemsSource>
                    </Picker>
                </Grid>
            </Grid>

        <Button 
            BackgroundColor="#2194EF"
            TextColor="White" 
            Text="Next" 
            HeightRequest="60"
            MinimumHeightRequest="60"
            IsEnabled="False"
            Command="{Binding RegistrationPageCommand}">
            <Button.Triggers>
                <MultiTrigger TargetType="Button">
                    <MultiTrigger.Conditions>
                        <BindingCondition Binding="{Binding SelectedCountry,
                                                       Converter={StaticResource stringNullOrEmptyValueBoolConverter }}" Value="false" />
                        <BindingCondition Binding="{Binding SelectedProvider,
                                                       Converter={StaticResource stringNullOrEmptyValueBoolConverter }}" Value="false" />
                    </MultiTrigger.Conditions>
        
                    <Setter Property="IsEnabled" Value="True" />
                </MultiTrigger>
            </Button.Triggers>
        </Button>

        </StackLayout>
    </ContentPage.Content>
</ContentPage>