Question

I'm trying to create a Border dynamicaly and tryning to add an Image into it.Is that possible ?

C# :

private void AddToHistory()
{
    HistoryBorder.Visibility = System.Windows.Visibility.Visible;
    Border Br = new Border();
    Br.BorderBrush = Brushes.Black;   
    Br.BorderThickness = new Thickness(2) ;                
    Image tem = new Image();
    tem.Source = image1.Source;
    Br.Content = tem;   // ?? Error here.  
    StackHistory.Children.Add(Br);   
}

XAML :

<Grid Grid.Column="2" x:Name="History">
  <ScrollViewer>
    <Border x:Name="HistoryBorder" BorderThickness="4" CornerRadius="1" BorderBrush="#FFF2C683" Visibility="Hidden">
       <StackPanel x:Name="StackHistory" HorizontalAlignment="Left" VerticalAlignment="Top" >
       </StackPanel>
    </Border>
  </ScrollViewer>
</Grid>
Was it helpful?

Solution

You need to set Border.Child instead of Content

Br.Child = tem;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top