Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning Windows Phone 7 Application Development: Building Windows Phone Applications Using S
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Windows Phone 7 Application Development: Building Windows Phone Applications Using S
This is the forum to discuss the Wrox book Beginning Windows Phone 7 Application Development: Building Windows Phone Applications Using Silverlight and XNA by Nick Lecrenski, Karli Watson, Robert Fonseca-Ensor; ISBN: 978-0-470-91233-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Windows Phone 7 Application Development: Building Windows Phone Applications Using S section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 22nd, 2012, 01:27 PM
bmw bmw is offline
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Text to be changed, depending on the page that hosts the cotnrol

I followed the code on Page 130 Chapeter 4. The book mentions that Text to be changed, depending on the page that hosts the cotnrol. However it didn't have an example. Would anyone show or give an example or link to me. Thank in advance.
The following is my UserControl.xaml:

<UserControl x:Class="PhoneApp1.TitleControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">

<Grid x:Name="LayoutRoot">
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,10,28">
<TextBlock x:Name="ApplicationTitle" Style="{StaticResource appTitleStyle}"/>
<Grid Height="45" Style="{StaticResource pageTitleBackgroudStyle}">
<TextBlock x:Name="PageTitle" Margin="9,-7,0,17" Style="{StaticResource pageTitleStyle}"/>
</Grid>
</StackPanel>
</Grid>

The following is my UserControl.xaml.cs:
namespace PhoneApp1
{
public partial class TitleControl : UserControl
{
Example title;

public TitleControl()
{
InitializeComponent();

}

public TitleControl(Example e)
{

title = e;
InitializeComponent();

}

public string Caption
{
get { return title.DisplayText; }
}


}
public class Example
{

public Example(string strText)
{ DisplayText = strText; }

public string DisplayText { get; set; }

}
}


This is my MainPage.xaml:
<StackPanel x:Name="Titleqq" Grid.Row="0" Margin="12,17,0,28" Grid.ColumnSpan="2">
<local:TitleControl x:name="Title" />
</StackPanel>
Reply With Quote
  #2 (permalink)  
Old March 23rd, 2012, 12:03 PM
bmw bmw is offline
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Text to be changed, depending on the page that hosts the cotnrol solution

I found the solution by myself. I need to register DependencyProperty. There is my code.
PageTitle.xaml
Code:
  <UserControl x:Name="TitleControl" x:Class="PhoneApp1.PageTitle"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="480">

    <Grid x:Name="LayoutRoot" >        
        <StackPanel x:Name="TitlePanel" Margin="4,17,10,28" Grid.Column="1" >
            <TextBlock x:Name="ApplicationTitle" Text="CSM Phone Application"   Style="{StaticResource appTitleStyle}"  />
            <Grid  Height="45" Style="{StaticResource pageTitleBackgroudStyle}">
                <TextBlock Text="{Binding Path=TitleCaption,  ElementName=TitleControl }" Style="{StaticResource pageTitleStyle}"
                           TextAlignment="{Binding}" />
            </Grid>
        </StackPanel>
    </Grid>
</UserControl>
The code behind of the PageTitle.xaml
Code:
//http://alan.beech.me.uk/2011/04/25/adding-a-dependency-property-to-a-wp7-usercontrol/

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;

namespace PhoneApp1
{
    public partial class PageTitle : UserControl
    {
        public PageTitle()
        {
            InitializeComponent();
        }

        public static DependencyProperty TitleCaptionProperty =
     DependencyProperty.Register("TitleCaption", typeof(string), typeof(PageTitle), null);

        public string TitleCaption
        {
            get
            {
                return (string)GetValue(TitleCaptionProperty);
            }
            set
            {
                SetValue(TitleCaptionProperty, value);
            }
        }

    }
}
On the mainPage.xml
Code:
  <StackPanel x:Name="Titleqq" Grid.Row="0" Margin="12,17,0,28" Grid.ColumnSpan="2" >                       
            <my:PageTitle TitleCaption="LOGIN" />
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating TC fields when a matching text is changed! arefkr Word VBA 6 May 24th, 2010 08:13 PM
depending on role acessing same default page veda ASP.NET 2.0 Basics 0 July 11th, 2008 06:43 AM
track page data has changed webmahesh XSLT 1 December 12th, 2007 06:54 PM
using textbox keypress/text changed bazookajoe76 C# 5 October 10th, 2004 01:03 AM
Displaying text depending on the value of a field lguzman Access VBA 1 May 30th, 2004 07:14 PM



All times are GMT -4. The time now is 01:43 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.