menuitem color to change

pintu1228

New member
Joined
Feb 23, 2015
Messages
1
Programming Experience
Beginner
I need some help fixing my windows phone application program in C#. I need help in figuring out how to use the menuitem color to change from color to color when I click on it under each button (SOS and strobe).


The point of the program is to make a app that will act like a flashlight. The two icons on the bottom will be SOS and Strobe; when you click on SOS it will display whatever color is selected with the SOS sequence and when you click on Strobe it will flash the color you choose. (the color by default will be white).


If anyone could help me figure this out, I would be grateful.
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Media;


namespace Assgn2_v1_0
{
    public partial class MainPage : PhoneApplicationPage
    {
        
        private void BSOSIcon_Click(object sender, EventArgs e)
        {
            ApplicationBarIconButton btn = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
                //btn.Text = "pause";
                //MessageBox.Show("SOS works!");
                btn.IconUri = new Uri("/Images/appbar.cancel.rest.png", UriKind.Relative);
                //String clr = (sender as IApplicationBarMenuItem).Text;
                btn.IsEnabled = false;
                String clr = "white";


                this.onBrush = (SolidColorBrush)this.Resources[clr];
                this.ContentPanel.Background = onBrush;
       
        }
        private void BSTROBEIcon_Click(object sender, EventArgs e)
        {
            ApplicationBarIconButton btn = (ApplicationBarIconButton)ApplicationBar.Buttons[1];
            
                //btn.Text = "pause";
                //MessageBox.Show("STROBE works!");
                String clr1 = "green";


                this.onBrush = (SolidColorBrush)this.Resources[clr1];
                this.ContentPanel.Background = onBrush;
                btn.IconUri = new Uri("/Images/appbar.cancel.rest.png", UriKind.Relative);
                btn.IsEnabled = false;
                //SOSIcon.IconUri = new Uri("/Images/appbar_sync_rest.png", UriKind.Relative);
            //SOSIcon.IsEnabled = true;
        }


        private void MenuItem_click (object sender, EventArgs e)
        {
            ApplicationBarMenuItem menuItem1 = new ApplicationBarMenuItem();
            menuItem1.Text = "red";
            ApplicationBar.MenuItems.Add(menuItem1);
            menuItem1.Click += new EventHandler(menuItem1_Click);


    }
}

<phone:PhoneApplicationPage 
    x:Class="Assgn2_v1_0.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
    
    <phone:PhoneApplicationPage.Resources>
        <SolidColorBrush x:Key="white"> White</SolidColorBrush>
        <SolidColorBrush x:Key="green"> Green</SolidColorBrush>
        <SolidColorBrush x:Key="red"> Red</SolidColorBrush>
        <SolidColorBrush x:Key="orange"> Orange</SolidColorBrush>
        <SolidColorBrush x:Key="yellow"> Yellow</SolidColorBrush>
        <SolidColorBrush x:Key="cyan"> Cyan</SolidColorBrush>
        <SolidColorBrush x:Key="purple"> Purple</SolidColorBrush>
        <SolidColorBrush x:Key="gray"> Gray</SolidColorBrush>
    </phone:PhoneApplicationPage.Resources>
    
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <!--<shell:ApplicationBarIconButton IconUri="/Images/sosflash_62.png" Text="SOS"/>-->
            <shell:ApplicationBarIconButton x:Name="SOSIcon" IconUri="/Assets/AppBar/appbar.refresh.rest.png" Text="SOS" Click="BSOSIcon_Click"/>
            <shell:ApplicationBarIconButton x:Name="STROBEIcon" IconUri="Assets/AppBar/appbar.refresh.rest.png" Text="STROBE" Click="BSTROBEIcon_Click"/>
            <shell:ApplicationBarIconButton IconUri="/Assets/AppBar/appbar.refresh.rest.png" Text="test"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="red"/>
                <shell:ApplicationBarMenuItem Text="orange"/>
                <shell:ApplicationBarMenuItem Text="yellow"/>
                <shell:ApplicationBarMenuItem Text="green"/>
                <shell:ApplicationBarMenuItem Text="cyan"/>
                <shell:ApplicationBarMenuItem Text="purple"/>
                <shell:ApplicationBarMenuItem Text="gray"/>
                <shell:ApplicationBarMenuItem Text="white"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <!--TitlePanel contains the name of the application and page title-->
<!--        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>
-->
        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="10,-10,14,10"></Grid>
    </Grid>
 
</phone:PhoneApplicationPage>
 
Back
Top Bottom