Xaml e、 SelectedItem.ToString()生成类名Xamarin.Forms
我是Xamarin.Forms的新手,尽管我进行了搜索,但在获取与ListView中的选定项可绑定属性关联的字符串时失败。目标是根据所选项目采取行动。我在XAML中定义了我的UI,如下所示:Xaml e、 SelectedItem.ToString()生成类名Xamarin.Forms,xaml,listview,xamarin,xamarin.forms,selecteditem,Xaml,Listview,Xamarin,Xamarin.forms,Selecteditem,我是Xamarin.Forms的新手,尽管我进行了搜索,但在获取与ListView中的选定项可绑定属性关联的字符串时失败。目标是根据所选项目采取行动。我在XAML中定义了我的UI,如下所示: <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="EdgeNet.Ed
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="EdgeNet.EdgeNetAddModule">
<StackLayout Padding="10">
<Label Text="" FontSize="12" />
<Label Text="Add Module" TextColor="#00A79D" HorizontalOptions="Center" FontSize="36"/>
<Label Text="" FontSize="12"/>
<ListView x:Name="moduleTypesListView"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Header="Select A Module"
ItemSelected="OnSelection"
RowHeight="80">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" TextColor="#00A79D" Detail="{Binding Detail}" DetailColor="#A7A9AC"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Image Source="Logo.png" />
moduleTypesListView.ItemsSource = new ObservableCollection<Products>()
{
new Products {Name = "Outlet", Detail = "Standard 3-Prong Residential"},
new Products {Name = "Switch", Detail = "Standard Wall Switch"},
new Products {Name = "Thermostat", Detail = "edgeNet Smart Thermostat"}
};
提前感谢您的帮助。我确信我在这里遗漏了一些简单的东西,只是不确定它是什么。
e.SelectedItem
是一个产品
,因此您可以强制转换它,然后访问它的属性
var product = (Product) e.SelectedItem;
if (product.Name == "blah") {
...
}
e.SelectedItem
是一种产品
,因此您可以对其进行强制转换,然后访问其属性
var product = (Product) e.SelectedItem;
if (product.Name == "blah") {
...
}
非常感谢你!我知道我错过了一些简单的东西。非常感谢!我知道我错过了一些简单的事情。