Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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>
 
Old March 23rd, 2012, 11:03 AM
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" />




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 07:13 PM
depending on role acessing same default page veda ASP.NET 2.0 Basics 0 July 11th, 2008 05: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 12:03 AM
Displaying text depending on the value of a field lguzman Access VBA 1 May 30th, 2004 06:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.