This project is read-only.

About Object Effect region in different Views.

Jul 15, 2010 at 8:38 AM

my code :

one ViewModel:  has two public property  and one public ActionCommand

 

[MapViewModel(typeof(Views.MoniSectionTopicView))]
[DefineNavigationContent("Views/MiniSectionTopicView/", typeof(Views.MoniSectionTopicView))]

public class MoniSectionTopicViewModel : NavigationViewModelBase
    {

          public IEnumerable<WQ_MoniScheme> MoniSchemes { get; private set; }

          public IEnumerable<WQ_MoniTask> MoniTasks { get; private set; }

          public nRoute.Components.ActionCommand LoadMoniTaskCommand { get; private set; }

}

 and the related View:

public partial class MoniSectionTopicView : UserControl
    {
        public MoniSectionTopicView()
        {
            InitializeComponent();
            
        }
    }

 

two  Views without ViewModel:

[MapNavigationContent("Views/MoniSchemeListingView/")]
    public partial class MoniSchemeListingView : UserControl
    {
        public MoniSchemeListingView()
        {
            InitializeComponent();
            
        }
    }

[MapNavigationContent("Views/MoniTaskListingView/")]
    public partial class MoniTaskListingView : UserControl
    {
        public MoniTaskListingView()
        {
            InitializeComponent();
            
        }
    }

 

both view has a listbox.:

MoniSchemeListingView.xaml  :  

<Grid x:Name="LayoutRoot" Background="Green">
        <ListBox x:Name="MoniSchemeListBox"
                 ItemsSource="{Binding MoniSchemes}"
                 ItemTemplate="{StaticResource MoniSchemeItemTemplate}">         
        </ListBox>    
    </Grid>

MoniTaskListingView.xaml:

<Grid x:Name="LayoutRoot" Background="Green">
        <ListBox x:Name="MoniTaskListBox"
                 ItemsSource="{Binding MoniTasks}"
                 ItemTemplate="{StaticResource MoniTaskItemTemplate}">

        </ListBox>
    </Grid>

now my question is 

1. why i can bind MoniSchemes and MoniTasks correctly?  it seems that there is no direct relation between MoniSectionTopicViewModel and MoniSchemeListingView or MoniTaskListingView.

2. if i can use public property of the MoniSectionTopicViewModel, why i can't trigger the LoadMoniTaskCommand of that viewmodel in the MoniSchemeListingView or MoniTaskListingView?

 

one suggestion:  can you just add  more debug infomation in the nRoute.  just like today i use the browsingcontainer,

<nRoute:BrowsingContainer x:Name="BrowsingContainer" >
                <i:Interaction.Behaviors>
                    <nRoute:NavigationHandlerBehavior HandlerName="STSBrowsingContainer"/>
                </i:Interaction.Behaviors>
            </nRoute:BrowsingContainer>

then a button :

<Button Height="28" Style="{StaticResource BackButtonStyle}" Margin="5,0,0,0">
                    <i:Interaction.Behaviors>
                        <behaviors:NavigateBackInfoBehavior BrowsingContainer="{Binding ElementName='STSBrowsingContainer'}"/>
                    </i:Interaction.Behaviors>
                </Button>

i find that it does't work. and i find the reason for a long time,  at last , it's because i use the wrong ElementName, it should be 'BrowsingContainer' insted of 'STSBrowsingContainer'}".. oh my god!

if it brings a eror,when it finds that there is no Element that has a name as STSBrowsingContainer, i think it will be more convconvenient.

 

 

 

Jul 15, 2010 at 5:09 PM

Hi, from what you've described I'm making a guess that MoniSchemeListingView and MoniTaskListingView are contained within the MoniSectionTopicView? If that is indeed the case, then all that is happing is that the DataContext is flowing to the children from the parent, hence you are able to bind to the exposed properties. This is the normal and expected behavior, now per the same logic, you should be able to bind and execute the command. Can you show me the xaml for how you've hooked up the commands? 

Secondly, thanks, I've noted the need for both better tracing and debugging info - I know it is an issue..
Cheers,

Rishi 

Jul 16, 2010 at 3:07 AM
Edited Jul 16, 2010 at 4:16 AM

yes, you are right.

now  i find the problem.  see in my code, there are two Command, one can trigger, but another can not.  because it's in an DataTemplate????

by the way .  if i click the HyperlinkButton in the ListBox's ItemTemplate ,i  want to set the ListBox's SelectItem the current one.  any idea to implement???  thanks!!!!

    <UserControl.Resources>

        <DataTemplate x:Key="MoniSchemeItemTemplate">
            <Border  Margin="3" CornerRadius="3" >
                <Grid Cursor="Hand">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>

   
                    <StackPanel Orientation="Horizontal" Grid.Row="0">
                        <HyperlinkButton x:Name="NameButton"  Content="{Binding scheme_name}"  
                                         Style="{StaticResource HyperlinkButtonFirstStyle}"
                                         ToolTipService.ToolTip="name"
                                         >
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                </i:EventTrigger>
                            </i:Interaction.Triggers>

                        </HyperlinkButton>
                        <TextBlock Text="  "/>
                        
                    </StackPanel>

                    <StackPanel Orientation="Horizontal" Grid.Row="1">
                        <HyperlinkButton Content="task" Style="{StaticResource HyperlinkButtonMinorStyle}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <nRoute:ExecuteCommandAction Command="{Binding LoadMoniTaskCommand}"/>                                  **************************************This one can not be triggered
                                    <nRoute:NavigateAction Url="MoniSection/Views/MoniTaskListingView/" HandlerName="STSBrowsingContainer"></nRoute:NavigateAction>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </HyperlinkButton>
                                         
                        <TextBlock Text="  "/>
                    </StackPanel>
                </Grid>
            </Border>
        </DataTemplate>
        
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot" Background="Green">
        <ListBox x:Name="MoniSchemeListBox"
                 ItemsSource="{Binding MoniSchemes}"
                 ItemTemplate="{StaticResource MoniSchemeItemTemplate}"
                 SelectedItem="{Binding CurrentMoniScheme, Mode=TwoWay}"
                >         
        </ListBox>
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Loaded">
                <nRoute:ExecuteCommandAction Command="{Binding LoadMoniSchemeCommand}"/>    **********************************************This one can be triggered correctly
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </Grid>
</UserControl>

Jul 16, 2010 at 10:08 AM

Well, have a look at the Relaying Command section of this blog post:

http://www.orktane.com/Blog/post/2009/11/03/I-Command-MVVM.aspx

Rishi