【问题标题】:XAML background color and text color not changingXAML 背景颜色和文本颜色不变
【发布时间】:2018-02-27 04:41:09
【问题描述】:

我不知道我的代码是否显示FOOS 列表。它确实生成了一个可点击的列表项,该列表项转到正确的详细信息页面,问题是列表项为空白或所有文本均为白色.我不知道是哪个。

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MaopApplication.Views.PipelineSearch">
    <StackLayout Orientation="Vertical">
        <StackLayout Orientation="Horizontal"  >
            <Entry Placeholder="Search With PipelineName" Text="{Binding SearchText}"  ></Entry>
            <Button Text="Search" Command="{Binding SearchPipes}"    />
        </StackLayout>
        <ListView ItemsSource="{Binding Foos}"  ItemTapped="OnListViewItemTapped" ItemSelected="OnListViewItemSelected">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View BackgroundColor="Red">
                            <StackLayout>
                                <label Text="wtf" TextColor="Black"></label>
                                <label Text="{Binding Test}"TextColor="Black"/>
                             </StackLayout>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage>

创建 FOOS 的代码

var Foos = new List&lt;object&gt;() {new {Test = "foo"}, new {Test = "bar"}};

【问题讨论】:

  • 很奇怪。您是否在“输出”窗口中看到任何错误消息?你能把你用来填写Foos的代码贴出来吗?
  • 无错误。完全没有
  • 你可以试试 listview: VerticalOptions="FillAndExpand"
  • 调试 Xamarin Forms 时要尝试的随机操作...重新启动设备/模拟器,重置设备/模拟器,重新启动 Visual Studio,重新启动计算机...... '没有在增量构建中获取,要么从设备中删除应用程序并清理解决方案......

标签: xaml xamarin xamarin.forms


【解决方案1】:

这里有几处错误(可能只是复制/粘贴工作不好):

  • ViewCell.View 没有 BackgroundColor 属性,请改用 StackLayout.BackgroundColor
  • label 应该是 Label(大写问题)

当我对您的代码进行这些更改时,它对我来说运行良好:

<ViewCell>
  <ViewCell.View>
    <StackLayout BackgroundColor="Red">
      <Label Text="wtf" TextColor="Black"/>
      <label Text="{Binding Test}" TextColor="Black"/>
    </StackLayout>
  </ViewCell.View>
</ViewCell>

【讨论】:

  • 非常感谢
猜你喜欢
  • 2018-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多