简体   繁体   English

Windows Phone应用程序更改透视页面项目的颜色,甚至是奇数

[英]Windows phone app change color of pivot page items even odd

I have built Windows phone app now I want to change pivot page items color on the base of even odd items. 我现在已经构建了Windows Phone应用,我想基于偶数项更改透视页项的颜色。 How it is possible? 怎么可能? any solution will be appreciated. 任何解决方案将不胜感激。

Here is some code example: 这是一些代码示例:

<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>

I want to change color of item in code behind. 我想在后面的代码中更改项目的颜色。

    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;
     }

    }

Email manager email inbox code 电子邮件管理员的电子邮件收件箱代码

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" });
 }

}

Okay I got solution, want to share. 好吧,我有解决方案,想分享。

if you want to change Foreground color of a list this simply use this: 如果要更改列表的前景颜色,则只需使用以下命令:

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

in mine code: 在我的代码中:

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

Also you can change color of grid child item like this way: 您也可以像这样更改网格子项的颜色:

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 is grid of page. ContentRoot是页面的网格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM