Windows手机应用程序更改透视页面项目的颜色甚至奇怪

本文关键字:颜色 项目 应用程序 手机 透视 Windows | 更新日期: 2023-09-27 18:33:07

我已经构建了Windows手机应用程序,现在我想在奇数项的基础上更改透视页面项目的颜色。怎么可能? 任何解决方案都将不胜感激。

下面是一些代码示例:

<PivotItem
            x:Uid="PivotItem1"
            Margin="19,152,0,-29.5"
            Header="Inbox"
            CommonNavigationTransitionInfo.IsStaggerElement="True">
            <ListView x:Name="myInbox"
                IsItemClickEnabled="True"
                ItemClick="ItemView_ItemClick"
                ContinuumNavigationTransitionInfo.ExitElementContainer="True" FontSize="36" Margin="-18,-139,-0.167,55.333">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="4*"/>
                                <ColumnDefinition Width="1*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition MinHeight="30" />
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Column="0" TextWrapping="NoWrap" Text="{Binding Subject}" FontSize="22" Grid.Row="0"></TextBlock>
                            <TextBlock Grid.Column="1" TextAlignment="Right" TextWrapping="NoWrap" Text="{Binding Date}" Grid.Row="0"></TextBlock>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </PivotItem>

我想在代码隐藏中更改项目的颜色。

    public sealed partial class PivotPage : Page
    {
    void PageLoaded(object sender, RoutedEventArgs e)
    {
        if (User.isLogedIn == false)
        {
            this.Frame.Navigate(typeof(Login));
        }
        else
        {
            LoadInbox(myInbox);                
        }
    }
    public async void LoadInbox(ListView list)
    {
                list.ItemsSource = EmailManager.EmailInbox;
     }
    }
电子邮件

管理器电子邮件收件箱代码

class EmailManager
{
    public static List<EmailMessage> EmailInbox;

 public EmailManager(){
   EmaiInbox.Add(new EmailMessage { Id = 1, Subject = "my email subject one with long long text header", Date = "12-Dec-2015 05:10", Contents = "Following the comments on the question, one possible answer would be to suscribe to the Loaded event of your page and call the Event method from there.", Sender = "abc@example.com" });
            EmaiInbox.Add(new EmailMessage { Id = 2, Subject = "my email subject 2", Date = "12-Dec-2015 07:25", Contents = "Following the comments on the question, one possible answer would be to suscribe to the Loaded event of your page and call the Event method from there.", Sender = "abc@example.com" });
 }
}

Windows手机应用程序更改透视页面项目的颜色甚至奇怪

好的,我有解决方案,想分享。

如果要更改列表的前景色,只需使用以下命令:

yourlist.Foreground = new SolidColorBrush(Colors.Red);

在矿代码中:

else
    {
        LoadInbox(myInbox);                   
         /// myInbox.Background = new SolidColorBrush(Colors.Red);
          myInbox.Foreground = new SolidColorBrush(Colors.Red);
          myOutbox.Foreground = new SolidColorBrush(Colors.Red);
     }

您也可以像这样更改网格子项的颜色:

public YourConstructor() // replace YourConstructor with your class name.
    {
        this.InitializeComponent();
        this.navigationHelper = new NavigationHelper(this);
        this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
        this.navigationHelper.SaveState += this.NavigationHelper_SaveState;

        foreach (var c in ContentRoot.Children)
        {
            if (c.GetType() == typeof(TextBlock))
            {
                var c1 = c as TextBlock;
                c1.Foreground = new SolidColorBrush(Colors.Red);                  
            }
        }
    }

ContentRoot 是页面的网格。