Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing caliburn.micro with hierachical viewmodel structure
    primarykey
    data
    text
    <p>In a project I use <code>caliburn.micro</code> as MVVM framework.</p> <p>Now I have a somewhat big viewmodel for a master-details view.</p> <p>It is hierarchically built.</p> <p>Just to have a example:</p> <p>I have a <code>ComputerView</code> with a <code>ComputerViewModel</code>. Everything works fine here.</p> <p>Now this ComputerViewModel contains a <code>ObservableCollection&lt;HardwareComponentViewModel&gt;</code></p> <p>This <code>HardwareViewModel</code> has no <code>View</code> attached, it is just there to keep data in place. Caliburn does not set up <code>Binding</code> correctly here. (I cannot use a <code>x:name</code> to get a <code>Binding</code>)</p> <p>Until now, that was no problem as I could use the "normal" Binding way. Now I need to add a <code>ActionMessage</code> to a grid in the <code>HardwareComponentViewModel</code>.</p> <p>To make more clear what I mean, here is the full XAML to reproduce it</p> <pre><code>&lt;UserControl x:Class="DemoApplication.Views.ComputersView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cal="http://www.caliburnproject.org" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:s="clr-namespace:System;assembly=mscorlib" d:DesignHeight="300" d:DesignWidth="300" mc:Ignorable="d"&gt; &lt;Grid&gt; &lt;Grid.Resources /&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="10*" /&gt; &lt;RowDefinition Height="2*" /&gt; &lt;RowDefinition Height="1*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="1*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Border HorizontalAlignment="Stretch" BorderBrush="Transparent" BorderThickness="0"&gt; &lt;ScrollViewer HorizontalContentAlignment="Stretch" Background="Yellow" BorderBrush="Transparent" BorderThickness="0" CanContentScroll="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"&gt; &lt;ListView x:Name="Computers" HorizontalContentAlignment="Stretch" Background="Red" BorderThickness="0"&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Border Background="Transparent" BorderBrush="Transparent" BorderThickness="0"&gt; &lt;ListView HorizontalContentAlignment="Stretch" Background="Black" ItemsSource="{Binding HardwareComponents}"&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Border Background="Aquamarine" BorderBrush="DarkGray" BorderThickness="1"&gt; &lt;Grid Background="Lime" cal:Message.Attach="[Event Click] = [Action Expand($dataContext)]"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="20" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt; &lt;/ScrollViewer&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p><strong>Update</strong></p> <p>1. Have tried <code>cal:Bind.Model="{Binding}"</code> on the UserControl, but no effect <a href="https://stackoverflow.com/questions/3650800/bind-a-command-to-a-button-inside-a-listview-with-caliburn-micro?rq=1">Took them from this question here</a></p> <p>2. In the Grid I tried: <code>cal:Message.Attach="[Event Click] = [Action Expand]"</code> but did not work either</p> <p>3. I added Logging now and get </p> <p>Action Convention Not Applied: No actionable element for Expand.</p> <p>But I do not know what it tries to tell me. Perhaps no action can be applied to Grid?</p> <p>4. Have now bound it to a button inside the grid, this works. As a parameter I pass the datacontext, which is indeed the HardwareComponentViewModel, but it is bubbled to the most outside ViewModel, where the Binding is set up correctly (ComputerViewModel).</p> <pre><code>&lt;Button cal:Message.Attach="[Event Click] = [Action Expand($dataContext)]"&gt; </code></pre> <p><strong>So the question is: What do I have to do to get Binding set up correctly? What do I have to do to get ActionMessages in HardwareComponentViewModel called?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload