Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight: Animate a data-template property / bind to code-behind?
    primarykey
    data
    text
    <p>I'm building a Windows Phone 7 app. For it, I'm making a <code>ListBox</code> that has two modes: editing and not-editing. When it's in editing mode, <code>+</code> and <code>-</code> icons are displayed next to the items. When it's in normal modes, the icons are hidden.</p> <p>I'm trying to figure out how to do this. Here is the control:</p> <pre><code> &lt;Grid x:Name="LayoutRoot"&gt; &lt;ListBox x:Name="ContentListBox"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto"/&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Image Source="{Binding Path=IconSource}" Grid.Column="0" Width="96" Height="96" VerticalAlignment="Center" /&gt; &lt;TextBlock Text="{Binding Path=Name}" Grid.Column="1" /&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;/Grid&gt; </code></pre> <p>Ideally, I'd like to animate the icons first column to slide from <code>Width="0"</code> to <code>Width="Auto"</code>. I looked into Visual States, but was unsure how to use them.</p> <p>For testing purposes, I am now trying to just bind the first column's visibility to some property indicating if we are in editing mode or not. </p> <p>I could set <code>Width</code> of the first column from code-behind, but I'm not sure how to do that.</p> <p>I tried setting <code>Visibility</code> on <code>ColumnDefinition</code>, but it complained that no such element exists. </p> <p>I could set <code>Visibility</code> on each <code>Image</code>. Ideally, I'd like to bind it to a property in the code-behind instead of a property on each item in the list box. I tried this, but was unable to get it to work:</p> <p>Code behind:</p> <pre><code>public bool Editing { get; set; } </code></pre> <p>XAML:</p> <pre><code> &lt;Image Source="{Binding Path=IconSource}" Grid.Column="0" Width="96" Height="96" VerticalAlignment="Center" Visibility="{Binding Path=Editing, Converter={StaticResource visibilityConverter}}" /&gt; </code></pre> <p>What else can I try? Am I doing something wrong? Ideally, I'd like to just use Visual States.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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