【发布时间】:2016-10-20 17:37:02
【问题描述】:
我正在制作一个 XAML 应用程序,但在将我的 xaml 文件与其类绑定时遇到了一些问题。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="App.TestXaml"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ContentPage.Content>
<ListView x:Name="ListTest">
<Label FontSize="12" x:Name="test1"/>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Spacing="5" Orientation="Horizontal">
<Label FontSize="14" x:Name="test2"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
在我的 cs 文件 testXaml.cs 中链接到这个 xaml :
test1.FontSize = 20 ;
// 有效 - 它检测该标签的 test1 变量。
然而,在我的列表视图中,当我尝试访问名为 test2 的标签时,它没有在我的 cs 文件中检测到它
test2.FontSize = 24 ;
// 类未检测到test2(当前上下文中不存在名称test2)
知道如何解决这个问题或为我的cs文件中的列表项设置一个值吗?
【问题讨论】:
标签: c# wpf xaml listview xamarin