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

时间:2016-02-04 10:39:15

标签: c# windows-phone-8.1

我现在已经构建了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" });
 }

}

1 个答案:

答案 0 :(得分:0)

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

如果您想更改列表的前景色,请使用以下命令:

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是网页。