Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are my images not showing up in my UserControl?
    primarykey
    data
    text
    <p>I have a <code>ContentPresenter</code> that displays a <code>UserControl</code>. The <code>UserControl</code> contains an <code>ItemsControl</code> that binds to a list of images. When I change the <code>DataContext</code> for my <code>UserControl</code> the Images are there, they just aren't displaying. I think what is happening is they are just stacking on top of each other instead of wrapping, but I don't know why. Here is some code to give you a better idea of what I am working with.</p> <p><strong>Edit:</strong> To get a better of idea of how the program flows here is what is going on. <code>ListOfScreenShots</code> is another user control that displays images and buttons allowing users to select the images. As screen shots are selected they are added to a <code>List&lt;BitmapSource&gt;</code> and they are supposed to display in <code>EnlargedScreenShots</code>. Here is how the <code>UserControl</code> is applied</p> <p><code>private void MainWindowCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { if (e.Command == SelectImageCommand) { selectedImages.Add(e.Parameter as BitmapSource); ess.DataContext = selectedImages; this._contentPresenter2.Content = ess; } }</code></p> <p>Here is the xaml for <code>ListOfScreenShots</code>. That should also give a clearer understanding of what is going on.</p> <p><strong>ListOfScreenShots xaml:</strong></p> <pre><code> &lt;UserControl x:Class="Client.App.Support.ListOfScreenShots" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" xmlns:support="clr-namespace:Client.App.Support" d:DesignHeight="400" d:DesignWidth="800"&gt; &lt;Grid&gt; &lt;ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"&gt; &lt;ItemsControl Name="_listBox" ItemsSource="{Binding ''}"&gt; &lt;!--&lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;WrapPanel Orientation="Vertical"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt;--&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Image Name ="_thumbnailImage" Width="600" VerticalAlignment="Center" Source="{Binding ''}"/&gt; &lt;Button VerticalAlignment="Center" HorizontalAlignment="Center" Name="_addscreenshot" Content="Select Screenshot" Command="{x:Static support:SelectScreenShots.SelectImageCommand}" CommandParameter="{Binding ''}" Width="150" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; &lt;/ScrollViewer&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p><strong>Main Window xaml:</strong></p> <pre><code>&lt;dxc:DXWindow x:Class="Client.App.Support.SelectScreenShots" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/core" Focusable="False" IsTabStop="False" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:libRes="clr-namespace:Shared.Lib.Resources;assembly=Shared.Lib" xmlns:support="clr-namespace:Client.App.Support" Title="Select Images" Height="600" Width="800"&gt; &lt;Window.CommandBindings&gt; &lt;CommandBinding Command="support:SelectScreenShots.SelectImageCommand" Executed="MainWindowCommandBinding_Executed"/&gt; &lt;/Window.CommandBindings&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="367"/&gt; &lt;RowDefinition Height="167"/&gt; &lt;RowDefinition Height="33"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;ContentPresenter Grid.Row="0" Name="_contentPresenter" Content="{Binding ''}"/&gt; &lt;ContentPresenter Grid.Row="1" Name="_contentPresenter2" Content="{Binding ''}"/&gt; &lt;StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal"&gt; &lt;Button Name="_OK_Button" Content="OK" Click="_OK_Button_Click" Margin="0,5,5,5" Width="75" Height="23"/&gt; &lt;Button Name="_Cancel_Button" Content="Cancel" Click="_Cancel_Button_Click" Margin="0,5,5,5" Width="75" Height="23"/&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>Main Window code behind:</p> <pre><code> public partial class SelectScreenShots : DXWindow { public static readonly RoutedCommand SelectImageCommand = new RoutedCommand(); public static List&lt;BitmapSource&gt; selectedImages = new List&lt;BitmapSource&gt;(); public static List&lt;BitmapSource&gt; screenshots = new List&lt;BitmapSource&gt;(); public static ListOfScreenShots loss = new ListOfScreenShots(); public static EnlargedScreenShot ess = new EnlargedScreenShot(); public SelectScreenShots() { Client.GUI.AppGUI.SetupTheme(this); InitializeComponent(); screenshots = RenderWindows(); loss.DataContext = screenshots; this._contentPresenter.Content = loss; } public static List&lt;BitmapSource&gt; RenderWindows() { var windows = Application.Current.Windows .OfType&lt;Window&gt;() .Where(x =&gt; x.GetType() != typeof(AskAQuestionDialog) &amp; x.GetType() != typeof(SelectScreenShots)); var bitmaps = new List&lt;BitmapSource&gt;(); foreach (var window in windows) { var bitmap = new RenderTargetBitmap((int)window.Width, (int)window.Height, 96d, 96d, PixelFormats.Default); bitmap.Render(window); bitmaps.Add(bitmap); } return bitmaps; } private void MainWindowCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { if (e.Command == SelectImageCommand) { selectedImages.Add(e.Parameter as BitmapSource); ess.DataContext = selectedImages; this._contentPresenter2.Content = ess; } } private void _OK_Button_Click(object sender, RoutedEventArgs e) { this.Close(); } private void _Cancel_Button_Click(object sender, RoutedEventArgs e) { this.Close(); } } } </code></pre> <p>User Control xaml:</p> <pre><code>&lt;UserControl x:Class="Client.App.Support.EnlargedScreenShot" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="162" d:DesignWidth="800"&gt; &lt;Grid&gt; &lt;ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;ItemsControl Name="_itemsControl" ItemsSource="{Binding ''}"&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;WrapPanel Orientation="Horizontal"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Image Name ="_thumbnailImage" HorizontalAlignment="Left" VerticalAlignment="Center" Source="{Binding ''}"/&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; &lt;/StackPanel&gt; &lt;/ScrollViewer&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>There are some other things going on as far as sizing and scroll bar visibility not working properly, but I will work those out later. Right now this is really bugging me.</p> <p>Anyone see anything obviously wrong. I am going to guess it has something to do with the fact that I have everything wrapped in a stack panel, but before I just had the image inside the <code>DataTemplate</code> wrapped in a <code>StackPanel</code> and it still didn't work. I also tried removing the <code>StackPanel</code> altogether and just using the <code>WrapPanel</code>.</p> <p>Any help would be greatly appreciated. Thank you.</p>
    singulars
    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.
 

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