David Shochet
David Shochet

Reputation: 5375

Binding Button to its handler by convention doesn't work

I have a WPF application with caliburn.micro. There is a user control MyView in a tab item of a tab control. Within that user control, there is another tab control. In one of its tabs, I added a button, and a corresponding method with the same name in the MyViewModel. But this method is not called when I click the button. Could you please tell what might cause it?

Thanks.

In the View:

            <TabControl SelectedIndex="{Binding SelectedTabIndex}">
...
            <TabItem x:Name="TextTab" Header="Text">

                    <Grid Grid.Row="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="10*"></RowDefinition>
                        <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <ScrollViewer Grid.Row="0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
...
                        </ScrollViewer>   
                        <Button Grid.Row="1" x:Name="SaveText" Content="Save" Width="50" Height="25" />
                    </Grid>

            </TabItem>

In the ViewModel:

   public void SaveText()
   {
  ...
   }

Upvotes: 1

Views: 107

Answers (1)

David Shochet
David Shochet

Reputation: 5375

I found a solution:

 <Button Grid.Row="1" x:Name="SaveText" cal:Message.Attach="SaveText" Content="Save" Width="50" Height="25" />

Still don't know why the convention didn't work without "Attach".

Upvotes: 1

Related Questions