Note that there are some explanatory texts on larger screens.

plurals
  1. POUnpredictable behavior of Action invocation in Caliburn Micro
    text
    copied!<p>I develop app for Windows Phone 7 with using of Caliburn Micro.</p> <p>Hear is a code of app's main parts.</p> <p>Part of <strong>MainView</strong>:</p> <pre><code>&lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt; &lt;controls:Panorama&gt; &lt;controls:PanoramaItem x:Name="SubPanoramaItem" DataContext="{Binding SubViewModel}"&gt; &lt;StackPanel&gt; &lt;toolkit:ListPicker ExpansionMode="FullScreenOnly" ItemsSource="{Binding DataModeList}"&gt; &lt;toolkit:ListPicker.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding Tag}" /&gt; &lt;/DataTemplate&gt; &lt;/toolkit:ListPicker.ItemTemplate&gt; &lt;toolkit:ListPicker.FullModeItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel x:Name="item" Margin="5, 24, 0, 24" cal:Action.TargetWithoutContext="{Binding ElementName=SubPanoramaItem, Path=DataContext}" cal:Message.Attach="[Event Tap] = [Action Tap($dataContext)]" Orientation="Horizontal"&gt; &lt;TextBlock FontSize="40" Text="{Binding PopupText}" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/toolkit:ListPicker.FullModeItemTemplate&gt; &lt;/toolkit:ListPicker&gt; &lt;/StackPanel&gt; &lt;/controls:PanoramaItem&gt; &lt;!-- Some other code --&gt; &lt;/controls:Panorama&gt; &lt;/Grid&gt; </code></pre> <p><strong>MainViewModel</strong>:</p> <pre><code>public class MainViewModel: Screen { public SubViewModel SubViewModel { get; private set; } public MainViewModel(SubViewModel subViewModel) { SubViewModel = subViewModel; } // some other code } </code></pre> <p><strong>SubViewModel</strong>:</p> <pre><code>public class SearchViewModel : Screen { private ObservableCollection&lt;DateModeItem&gt; _dataModeList = new ObservableCollection&lt;DateModeItem&gt;() { new DataItem { PopupText = "Item 1" }, new DataItem { PopupText = "Item 2" }, new DataItem { PopupText = "Item 3" }, new DataItem { PopupText = "Item 4" } }; public ObservableCollection&lt;DateModeItem&gt; DataModeList { get { return _dataModeList; } private set { _dataModeList = value; } } public void Tap(object dataContext) { var item = dataContext as DataItem; if (item != null) { var r = new Random(); switch (item.PopupText) { case "Item 1": item.Tag = r.Next(5); break; case "Item 2": item.Tag = r.Next(5, 10); break; case "Item 3": item.Tag = r.Next(10, 15); break; case "Item 4": item.Tag = r.Next(15, 20); break; } } } } </code></pre> <p><strong>DataItem</strong>:</p> <pre><code>public class DataItem { public string PopupText { get; set; } public int Tag { get; set; } } </code></pre> <p>As you can see I've attached Action to each StackPanel of DataTemplate in ListPicker. When tap occurs on the item in the list then new random tag must be generated. This tag is inserted into ListPicker's textbox.</p> <p>And this actions behave very strangely. When I tap on 1, 2 and 4 item, nothing happens at all. When I tap 3 item the app throws exception - "No target found for method Tap". And this what happens when I'm using ListPicker from Silverlight Toolkit.</p> <p>I've also triend RadListPicker from Telerik's RadConrols library. When I've used it, invocation of action method was unpredictable. Sometimes action invokes method correct. Sometimes nothing happen at all. One I can say surely - with tap on the last item it works less often in the correct way.</p> <p>What is going on? I can't understand.</p> <p><strong>Additional info:</strong></p> <p>I've made a cleaning of all unnecessary stuff from my app and left only code that I described above in the previous post.</p> <p>Now when I'm using ListPicker - nothing happens at all. List doesn't responds on taps. Sometimes app throws "No target found for method Tap" exception. When I'm using RadListPicker - almost always action not invoked and sometimes (very rarely) invoked correctly.</p>
 

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