MVVM Binding in Ribbon.Group

Ribbon for WPF Forum

Posted 8 years ago by Iwaneczko
Version: 11.1.0544
Avatar
I have a problem with Binding Text in MVVM pattern on simple textbox in Ribbon.Group.

xaml code:
<ribbon:Tab x:Class="Sato.ChartDocument.Ribbons.ChartDocumentRibbonTab"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
            xmlns:rv="clr-namespace:Sato.ChartDocument.Ribbons"
            xmlns:vm="clr-namespace:Sato.ChartDocument.ViewModels"
            Label="Chart Properties">
    <ribbon:Tab.DataContext>
        <vm:ChartDocumentViewModel/>
    </ribbon:Tab.DataContext>
    <ribbon:Group>
        <StackPanel Orientation="Horizontal">
            <Label Content="Chart Title" />
            <TextBox Text="{Binding Path=ChartTitle, Mode=TwoWay}" />
        </StackPanel>
    </ribbon:Group>
</ribbon:Tab>
and ChartDocumentViewModel code:
namespace Sato.ChartDocument.ViewModels
{
    using Microsoft.Practices.Prism.ViewModel;

    /// <summary>
    /// Description of chart document view model
    /// </summary>
    public class ChartDocumentViewModel : NotificationObject
    {
        private string chartTitle = "Tytuł ViewModel";

        /// <summary>
        /// Gets or sets the chart title.
        /// </summary>
        /// <value>
        /// The chart title.
        /// </value>
        public string ChartTitle
        {
            get { return chartTitle; }
            set
            {
                if (chartTitle != value)
                {
                    chartTitle = value;
                    RaisePropertyChanged(() => this.ChartTitle);
                }
            }
        }
    }
}
I have a breakpoint on ChartTitle.set, and it break just when I push button on other Ribbon.Tab.
I searched in forum, but I don't found anything.
How to resolve it?

[Modified at 08/01/2011 05:29 AM]

Comments (2)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The TextBox.Text property has a default UpdateSourceTrigger value of LostFocus. Perhaps change that on your binding to PropertyChanged instead.

Other than that, if it isn't firing correctly perhaps the LostFocus isn't occurring properly on the TextBox for the default update trigger since the Ribbon is in its own focus scope (same as a toolbar), and in separate focus scopes, focus can sometimes be handled differently.


Actipro Software Support

Posted 8 years ago by Iwaneczko
Avatar
Thank you very much, changing the UpdateSourceTrigger to Property changed solve it in 100%.
The latest build of this product (v2018.1 build 0675) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.