Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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# 如何在XAML页面中执行SetBinding和BindingContext?_C#_Xaml_Xamarin_Binding_Tabbedpage - Fatal编程技术网

C# 如何在XAML页面中执行SetBinding和BindingContext?

C# 如何在XAML页面中执行SetBinding和BindingContext?,c#,xaml,xamarin,binding,tabbedpage,C#,Xaml,Xamarin,Binding,Tabbedpage,我目前正在尝试开发一个基于Xamarin表单选项卡页面的应用程序。起初,应用程序只有一个用C#编写的内容页。我现在要做的是将这个现有的内容页面实现到选项卡式页面的一个选项卡中 我正在用XAML编写选项卡式页面,不知道如何用这种语言执行“SetBinding”或“BindingContext” 以下是我想将C#转换为XAML的内容: 在XAML中,这个C#代码的等价物是什么 我是这样开始的: <?xml version="1.0" encoding="utf-8" ?> <Tab

我目前正在尝试开发一个基于Xamarin表单选项卡页面的应用程序。起初,应用程序只有一个用C#编写的内容页。我现在要做的是将这个现有的内容页面实现到选项卡式页面的一个选项卡中

我正在用XAML编写选项卡式页面,不知道如何用这种语言执行“SetBinding”或“BindingContext”

以下是我想将C#转换为XAML的内容:

在XAML中,这个C#代码的等价物是什么

我是这样开始的:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TestBth.MyTabbedPage">
  <!--Pages can be added as references or inline-->
  <ContentPage Title="Connect">



        <ContentPage.Content>
            <StackLayout VerticalOptions="Center" HorizontalOptions="Center">

                <Picker x:Name="pickerBluetoothDevices" Title="Select a bth device"/>

                <Button x:Name="buttonConnect" Text="Connect"/>
                <Button x:Name="buttonDisconnect" Text="Disconnect"/>
                <Button x:Name="buttonSend" Text="Send"/>

                <ListView x:Name="lv"/>

            </StackLayout>

        </ContentPage.Content>

  </ContentPage>

为什么要在代码中创建绑定?您还可以在代码中进行绑定,例如,要将命令绑定到按钮,请使用:

<Button Command="{Binding ButtonCommand}"/>
您还需要在BindingContext实例中定义命令:

public ICommand ButtonCommand { get; set; }

您为什么要在代码中创建绑定?您还可以在代码中进行绑定,例如,要将命令绑定到按钮,请使用:

<Button Command="{Binding ButtonCommand}"/>
您还需要在BindingContext实例中定义命令:

public ICommand ButtonCommand { get; set; }

只要将c#binding属性更改为Xaml属性,就可以实现正确的操作

与c中的
ItemSourceProperty
类似,xaml绑定是
ItemSource

<StackLayout VerticalOptions="Center" HorizontalOptions="Center">

            <Picker x:Name="pickerBluetoothDevices" ItemsSource="{Binding ListOfDevices}" Title="Select a bth device" SelectedItem="{Binding SelectedBthDevice}" IsEnable="{Binding IsPickerEnabled}"/>

            <Button x:Name="buttonConnect" Text="Connect" Command="{Binding ConnectCommand}"/>
            <Button x:Name="buttonDisconnect" Text="Disconnect" Command="{Binding DisconnectCommand}"/>
            <Button x:Name="buttonSend" Text="Send" Command="{Binding SendCommand}"/>

            <ListView x:Name="lv" ItemSource="{Binding ListOfBarcodes}"/>

        </StackLayout>

只要将c#binding属性更改为Xaml属性就可以了

与c中的
ItemSourceProperty
类似,xaml绑定是
ItemSource

<StackLayout VerticalOptions="Center" HorizontalOptions="Center">

            <Picker x:Name="pickerBluetoothDevices" ItemsSource="{Binding ListOfDevices}" Title="Select a bth device" SelectedItem="{Binding SelectedBthDevice}" IsEnable="{Binding IsPickerEnabled}"/>

            <Button x:Name="buttonConnect" Text="Connect" Command="{Binding ConnectCommand}"/>
            <Button x:Name="buttonDisconnect" Text="Disconnect" Command="{Binding DisconnectCommand}"/>
            <Button x:Name="buttonSend" Text="Send" Command="{Binding SendCommand}"/>

            <ListView x:Name="lv" ItemSource="{Binding ListOfBarcodes}"/>

        </StackLayout>


我不知道需要在那里设置上下文。那真的很有用。非常感谢您的支持!当然如果您愿意,也可以在xaml内部进行:我不知道需要在那里设置上下文。那真的很有用。非常感谢您的支持!当然如果您愿意,也可以在xaml中执行此操作: