我正在尝试在代码中更改listview中特定项目的字体颜色,我不知道如何处理它。这就是我到目前为止所做的:
lv_options.ItemsSource = new Options[] {
new Options { Text = "Delete" },
new Options { Text = "Rename"} ,
new Options { Text = "Order: Move up" },
new Options { Text = "Order: Move down"}
};
if (act.item.SectionPosition >= act.lst_sections.Count() || act.item.SectionPosition <= 1)
{
foreach (Options op in lv_options.ItemsSource)
{
if(op.Text.Equals("Order: Move up"))
{
lv_options.HeaderTemplate.SetValue....???
}
}
}
这是我的列表视图
<ListView x:Name="lv_options">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="10, 15, 0, 15">
<Label Font = "20" Text="{Binding Text}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 0 :(得分:0)
您需要确定要更改的控件。 然后找到控件以添加属性。
实施例: 标签标签=(标签)ListViewID.FindControl(&#34; LabelID&#34;); label.Attributes.Add(&#34; color&#34;,&#34; red&#34;);
答案 1 :(得分:0)
int index = 1;
ListViewItem item = this.lv_options.ItemContainerGenerator.ContainerFromIndex(index) as ListViewItem;
item.Foreground = Brushes.Green;