[Version 2.0] Capture or rise event PropertyChanging in MVVM (IsFloating = true)

May 24, 2012 at 6:03 PM
Edited May 24, 2012 at 6:06 PM

Hello,

I have a problem of entrapment event "PropertyChanging" in MVVM. My intent is that after undocking (IsFloating = true) "LayoutDocument" and other changes to the properties as is the case of this event without using the MVVM pattern "myLayoutDocument.PropertyChanging + = new PropertyChangingEventHandler (ldStart_PropertyChanging)," I wanted to capture this event. They tried it according to example I AvalonDock with MVVM from there and when I define "LayoutItemContainerStyleSelector" ... <style TargetType="{x:Type avalondock:LayoutItem}"> the event "PropertyChanging" not present. Please advice how it can fix.

For nearly a reply in advance thanx

Forgive me my English ;)

 

Source: www.martin-mandak.com/MassWindows.rar

 


class
MainViewModels : ViewModelBase<MainViewModels> { #region Properties private ObservableCollection<LayoutDocument> _documentSource; public ObservableCollection<LayoutDocument> DocumentSource { get { return _documentSource; } set { if (_documentSource != value) { _documentSource = value; OnPropertyChanged(o => o.DocumentSource); } } } #endregion public MainViewModels() { Uri cestaStart = new Uri(@"\Images\Icons\forward_green.png", UriKind.Relative); LayoutDocument ldStart = new LayoutDocument(); ldStart.Title = "Start Page"; ldStart.Description = "TRUE"; ldStart.Content = new StartPage(); ldStart.IconSource = cestaStart; //this is the problem //----------------// ldStart.PropertyChanging += new PropertyChangingEventHandler(ldStart_PropertyChanging); //----------------// DocumentSource = new ObservableCollection<LayoutDocument>(); DocumentSource.Add(ldStart); } void ldStart_PropertyChanging(object sender, PropertyChangingEventArgs e) { } }

 

 

and XAML:

 

 

<Window.Resources>
        <mvvm:MainViewModels x:Key="MainViewModels" />
    </Window.Resources>

    <Grid x:Name="grid"  DataContext="{StaticResource MainViewModels}">
        <Grid.RowDefinitions>
            <RowDefinition Height="24"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Menu x:Name="menu" Grid.Row="0" />
        <avalondock:DockingManager 
            x:Name="rootDM" 
            Grid.Row="1" 
            DocumentsSource="{Binding DocumentSource}"
            >
            <avalondock:DockingManager.Theme>
                <avalondock:VS2010Theme/>
            </avalondock:DockingManager.Theme>

            <avalondock:DockingManager.LayoutItemContainerStyleSelector>
                <mvvm:PanesStyleSelector>
                    <mvvm:PanesStyleSelector.DockStyleStart>
                        <Style TargetType="{x:Type avalondock:LayoutItem}">
                            <Setter Property="IsSelected"  Value="True" />
                            <Setter Property="IsActive"  Value="True" />
                            <Setter Property="IconSource" Value="{Binding Model.IconSource}"/>
                            <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                            <Setter Property="Visibility" Value="{Binding Model.IsVisible}" />
                            <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/>
                            <Setter Property="Title" Value="{Binding Model.Title}"/>
                        </Style>
                    </mvvm:PanesStyleSelector.DockStyleStart>
                </mvvm:PanesStyleSelector>
            </avalondock:DockingManager.LayoutItemContainerStyleSelector>

            <avalondock:DockingManager.DocumentHeaderTemplateSelector>
                <mvvm:PanesTemplateSelector>
                    <mvvm:PanesTemplateSelector.LayoutDocument>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Width="16" Source="{Binding IconSource}" Margin="0,0,10,0" />
                                <TextBlock Text="{Binding Title}"/>
                            </StackPanel>
                        </DataTemplate>
                    </mvvm:PanesTemplateSelector.LayoutDocument>
                </mvvm:PanesTemplateSelector>
            </avalondock:DockingManager.DocumentHeaderTemplateSelector>

            <avalondock:DockingManager.LayoutItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="White">
                        <ContentControl Content="{Binding Content}">
                        </ContentControl>
                    </StackPanel>
                </DataTemplate>
            </avalondock:DockingManager.LayoutItemTemplate>

        </avalondock:DockingManager>
    </Grid>

 

May 24, 2012 at 8:21 PM

I think things will get a little messy for you, having LayoutDocuments in your MainViewModel, but I can understand a bit why you're going that route.  Sometimes perfect separation between model and view is way too complicated.

For the subject of knowing when the property changed, you might try http://joshsmithonwpf.wordpress.com/2009/07/11/one-way-to-avoid-messy-propertychanged-event-handling/.  

Just noticed you're looking at PropertyChanging, wouldn't you want PropertyChanged?

May 25, 2012 at 12:03 PM
Edited May 25, 2012 at 12:05 PM

.

May 25, 2012 at 12:05 PM
matelich wrote:

I think things will get a little messy for you, having LayoutDocuments in your MainViewModel, but I can understand a bit why you're going that route.  Sometimes perfect separation between model and view is way too complicated.

For the subject of knowing when the property changed, you might try http://joshsmithonwpf.wordpress.com/2009/07/11/one-way-to-avoid-messy-propertychanged-event-handling/.  

Just noticed you're looking at PropertyChanging, wouldn't you want PropertyChanged?

 

 

Thanx for you reply matelich,

I solve the problem of so doing binding DockingManager to ContentControl on View and then works this:

 

LayoutDocument.PropertyChanging += new PropertyChangingEventHandler(LayoutDocument_PropertyChanging);