none
Navigation Page, Title property XAML binding to view model possible?

    Question

  • Is it possible to somehow bind the Title property of the navigation:Page declaration to a view-model property?  The XAML I am attempting is:

    <navigation:Page
      x:Class="MyApp.Client.Home" 
      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"
      xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
      xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" 
      xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
      mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" 
      DataContext="{Binding Source={StaticResource vmLocator}, Path=HomeViewModel}" Title="{Binding PageTitle}" >
    
    

    And in doing this I get the following exception on the InitializeComponent call:

    Set property 'System.Windows.Controls.Page.Title' threw an exception.

    The Inner exception is:

    {System.ArgumentException: Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.String'.
       at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
       at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
       at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
       at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value)
       at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue)}

    Thanks in advance for any assistance.

     

    Thursday, October 21, 2010 11:36 AM

Answers

  • Hi. Title is not a dependency property, so it's not possible to use it in bindings.

    Take a look at this topic and scroll down to my last post. I've posted a code snippet for an attached property that allows you to set the title in Xaml via binding.

    Thursday, October 21, 2010 12:50 PM