title: How to cast in WPF
body: <p>I happened to have the need to bind a Grid's <code>DataContext</code> to a listview's <code>SelectedItem</code> property</p>
  
  <p>I could do that without any problem.... However, since the Listview's <code>SelectedItem</code> stores an object, the XAML editor does not know the type it is working with, which causes the following warning to be displayed : "Cannot resolve Property X in data context of type 'object'"</p>
  
  <p>Is there any way to specify in one of the bindings which type an object is (i searched for WPF casting but found no pertinent resources)</p>
  
  <p>Here is a relevant extract of my XAML : </p>
  
  <pre><code>&lt;ListView x:Name="ListView" ItemsSource="{Binding LoginScreens}" Grid.Column="0" Grid.Row="0" SelectionMode="Single"/&gt;
  &lt;Grid Grid.Column="1" Grid.Row="0" DataContext="{Binding SelectedItem, ElementName=ListView}"&gt;
      &lt;Grid.RowDefinitions&gt;
         /*rows*/
      &lt;/Grid.RowDefinitions&gt;
      &lt;Grid.ColumnDefinitions&gt;
        /*Columns*/
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;TextBox Grid.Row="0" Grid.Column="1" Style="{StaticResource TextBoxStyle}" Text="{Binding Name}"/&gt;
      &lt;TextBox Grid.Row="1" Grid.Column="1" Style="{StaticResource TextBoxStyle}" Text="{Binding NameFr}"/&gt;
      &lt;TextBox Grid.Row="2" Grid.Column="1" Style="{StaticResource TextBoxStyle}" IsEnabled="False" Text="{Binding Filename}"/&gt;
      &lt;TextBox Grid.Row="3" Grid.Column="1" Style="{StaticResource TextBoxStyle}" IsEnabled="False" Text="{Binding SHA1}"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>I tried the following syntax in the TextBox's bindings which didn't work : </p>
  
  <pre><code>&lt;TextBox Grid.Row="0" Grid.Column="1" Style="{StaticResource TextBoxStyle}" Text="{Binding (manifestEditor:LoginScreen.Filename)}"/&gt;
  </code></pre>
  
  <p>But it causes an error to be thrown about a key being null in a ListDictionary, so either i'm missing something or it is not the right way to go.</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>I'd like as much as possible to only use XAML to handle this</p>