Click here to Skip to main content
15,887,931 members
Home / Discussions / C#
   

C#

 
QuestionJavaScript functions calling C# functions and Viceversa Pin
Don Guy23-Nov-13 4:30
Don Guy23-Nov-13 4:30 
AnswerRe: JavaScript functions calling C# functions and Viceversa Pin
Dave Kreskowiak23-Nov-13 4:54
mveDave Kreskowiak23-Nov-13 4:54 
GeneralRe: JavaScript functions calling C# functions and Viceversa Pin
Don Guy23-Nov-13 5:55
Don Guy23-Nov-13 5:55 
GeneralRe: JavaScript functions calling C# functions and Viceversa Pin
Dave Kreskowiak23-Nov-13 7:13
mveDave Kreskowiak23-Nov-13 7:13 
AnswerRe: JavaScript functions calling C# functions and Viceversa Pin
jschell23-Nov-13 11:08
jschell23-Nov-13 11:08 
AnswerRe: JavaScript functions calling C# functions and Viceversa Pin
Elaine0023-Nov-13 22:17
Elaine0023-Nov-13 22:17 
GeneralRe: JavaScript functions calling C# functions and Viceversa Pin
Dave Kreskowiak25-Nov-13 2:23
mveDave Kreskowiak25-Nov-13 2:23 
QuestionTap not working Pin
Member 1037988622-Nov-13 8:57
Member 1037988622-Nov-13 8:57 
Hi I have created a windows phone app 7.1 that counts the taps, it has a reset button as well, I have coded it and no errors are showing, the app opens perfectly in the emulator but when you tap the screen no count happens, I have been through the code so many time Im nearly dizzy Smile | :) .

anyone who can spot anything wrong would very much appreciated.

--------------------------

MainPage.xaml.cs

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PhoneAppSolution
{
    public partial class MainPage : PhoneApplicationPage
    {
        int count = 0;
        //remember what the user typed for future actuvations or launches:
        Setting<int> savedCount = new Setting<int>("SavedCount", 0);

        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        //Handle a tap anywhere on the page (other than button)
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            this.count++;
            this.CountTextBlock.Text = this.count.ToString("NO");
        }
            //Handle a tap on the button
            void ResetButton_Click(object sender, RoutedEventArgs e)
            {
                this.count = 0;
                this.CountTextBlock.Text = this.count.ToString("NO");
            }
        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
     base.OnNavigatedFrom(e);
            // Persist state when leaving for any reason (Deactivated or Closing)
            this.savedCount.Value = this.count;
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
     base.OnNavigatedTo(e);
            // restore persisted value state:
            this.count = this.savedCount.Value;
            this.CountTextBlock.Text = this.count.ToString("NO");

}
}
}



-----------------------------------------------------------

Setting.cs

CSS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.IsolatedStorage;

namespace PhoneAppSolution
{
    public class Setting<num>
    {
        string name;
        num value;
        num defaultValue;
        bool hasValue;
        public Setting(string name, num defaultValue)
        {
            this.name = name;
            this.defaultValue = defaultValue;
        }

        public num Value
        {
            get
            {
                //check for cached value
                if(!this.hasValue)
                {
                    // try to get value from isolated storage
                    if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue(
                        this.name, out this.value))
                    {
                        //if this hasn't yet set
                        this.value = this.defaultValue;
                        IsolatedStorageSettings.ApplicationSettings[this.name] = this.value;
                    }
                    this.hasValue = true;
                }
                return this.value;
            }

            set
            {
                //save the value to isolated storage
                IsolatedStorageSettings.ApplicationSettings[this.name] = value;
                this.value = value;
                this.hasValue = true;

            }
        }

        public num DefaultValue
        {
            get { return this.DefaultValue; }
        }

        // "clear" cached value:
        public void ForceRefresh()
        {
            this.hasValue = false;
        }
    }
}



--------------------------------------------------------------

MainPage.xaml

XML
<phone:PhoneApplicationPage
    x:Class="PhoneAppSolution.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="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeHuge}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Margin="12,17,0,28" Grid.ColumnSpan="2">
            <TextBlock x:Name="ApplicationTitle" Text="Tally" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="tap to count" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--Row 1 text block containg count-->
            <TextBlock x:Name="CountTextBlock" Grid.Row="1" TextAlignment="Center" Text="0" Grid.ColumnSpan="2" />
        <!-- Row 2 : the reset button-->
            <Button x:Name="ResetButton" Grid.Row="1" Click="ResetButton_Click" Content="reset" Margin="21,343,1,143" />
    </Grid>

</phone:PhoneApplicationPage>




Any help really appreciated.

Paddy
AnswerRe: Tap not working Pin
TnTinMn23-Nov-13 11:31
TnTinMn23-Nov-13 11:31 
Questionhelp on shooping cart detect <Profile> at config Pin
MichaelCheong8922-Nov-13 1:35
MichaelCheong8922-Nov-13 1:35 
AnswerRe: help on shooping cart detect <Profile> at config Pin
Dave Kreskowiak22-Nov-13 1:40
mveDave Kreskowiak22-Nov-13 1:40 
GeneralRe: help on shooping cart detect <Profile> at config Pin
MichaelCheong8922-Nov-13 1:49
MichaelCheong8922-Nov-13 1:49 
GeneralRe: help on shooping cart detect <Profile> at config Pin
Dave Kreskowiak22-Nov-13 2:29
mveDave Kreskowiak22-Nov-13 2:29 
AnswerRe: help on shooping cart detect <Profile> at config Pin
OriginalGriff22-Nov-13 6:04
mveOriginalGriff22-Nov-13 6:04 
AnswerRe: help on shooping cart detect <Profile> at config Pin
MichaelCheong8922-Nov-13 7:14
MichaelCheong8922-Nov-13 7:14 
QuestionCentral Windows Application Authentication Pin
Zeyad Jalil22-Nov-13 1:00
professionalZeyad Jalil22-Nov-13 1:00 
AnswerRe: Central Windows Application Authentication Pin
Pete O'Hanlon22-Nov-13 1:11
mvePete O'Hanlon22-Nov-13 1:11 
GeneralRe: Central Windows Application Authentication Pin
Zeyad Jalil22-Nov-13 1:15
professionalZeyad Jalil22-Nov-13 1:15 
GeneralRe: Central Windows Application Authentication Pin
Pete O'Hanlon22-Nov-13 1:16
mvePete O'Hanlon22-Nov-13 1:16 
AnswerRe: Central Windows Application Authentication Pin
WuRunZhe22-Nov-13 3:00
WuRunZhe22-Nov-13 3:00 
GeneralRe: Central Windows Application Authentication Pin
Zeyad Jalil22-Nov-13 4:26
professionalZeyad Jalil22-Nov-13 4:26 
AnswerRe: Central Windows Application Authentication Pin
Dave Kreskowiak22-Nov-13 6:18
mveDave Kreskowiak22-Nov-13 6:18 
GeneralRe: Central Windows Application Authentication Pin
Eddy Vluggen22-Nov-13 7:05
professionalEddy Vluggen22-Nov-13 7:05 
GeneralRe: Central Windows Application Authentication Pin
Dave Kreskowiak22-Nov-13 12:38
mveDave Kreskowiak22-Nov-13 12:38 
QuestionNeed help with creating a cube mesh in Unity3D C# Pin
begginerc221-Nov-13 18:21
begginerc221-Nov-13 18:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.