Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding SelectedIndex property of a list to a property in different class in same/another project in Windows Phone 8?
    primarykey
    data
    text
    <p>There is something that I can't understand when I bind SelectedIndex of a list to a property. It works only if the property is part of the Codebehind of this XAML page</p> <p>for example : If there we have test.xaml , test.xaml.cs and AppSettings.cs , the binding works correctly only if the SelectedIndex property is bound to a property in test.xaml.cs</p> <p>After some trials , I found that if I set ItemSource and write all binding stuff in Code-behind , it works even if the property is in binder.cs !</p> <p>I think is related to the order of ItemSource and SelectedItem.</p> <p>The Code of the Property</p> <pre><code> private Currency sTileCurrency; public Currency STileCurrency { get { return GetValueorDefault&lt;Currency&gt;("STileCurrency", null); } set { sTileCurrency = value; if (AddOrUpdateValue("STileCurrency", value)) { settings.Save(); } } } </code></pre> <p>(This won't work !)</p> <pre><code> &lt;ListBox Name="sCurrencyLB" Margin="10,0,0,0" Width="Auto" Height="180" ItemsSource="{Binding SCurrencyList}" SelectedItem="{Binding STileCurrency, Source={StaticResource appSettings}, Mode=TwoWay}" &gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal" Margin="0,10,0,0"&gt; &lt;TextBlock Name="scountryNametb" Width="50" Text="{Binding code}" VerticalAlignment="Center" HorizontalAlignment="Right"/&gt; &lt;Image Source="{Binding imgUrl}" Height="50" Width="50" HorizontalAlignment="Left" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>But if we removed SelectedItem and ItemSource from XAML and set it in Codebehind (This will work !)</p> <pre><code> sCurrencyLB.ItemsSource = Binder.Instance.SCurrencyList; Binding binding = new Binding(); binding.Mode = BindingMode.TwoWay; binding.Source = settings; binding.Path = new PropertyPath("STileCurrency"); sCurrencyLB.SetBinding(ListBox.SelectedItemProperty, binding); </code></pre> <p>When I try to set ItemSource in XAML and Binding in Codebehind , it doesn't work too</p>
    singulars
    1. This table or related slice is empty.
    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.
    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