나는 UserControl
을 표시하는 ContentPresenter
입니다. UserControl
에는 이미지 목록에 바인딩하는 ItemsControl
이 포함되어 있습니다. 내 UserControl
에 대해 DataContext
을 변경하면 이미지가 표시되지만 표시되지 않습니다. 나는 일어나고 있다고 생각합니다. 그들은 포장하는 대신 서로 겹쳐서 쌓아 올리는 것입니다. 그러나 나는 왜 그런지 모르겠습니다. 내가하는 일을 더 잘 이해할 수있는 몇 가지 코드가 있습니다.내 이미지가 내 UserControl에 나타나지 않는 이유는 무엇입니까?
편집 : 여기서 프로그램이 어떻게 진행되는지에 대한 아이디어를 얻으려면 계속 진행되고 있습니다. ListOfScreenShots
은 사용자가 이미지를 선택할 수있는 이미지와 버튼을 표시하는 또 다른 사용자 컨트롤입니다. 스크린 샷을 선택하면 List<BitmapSource>
에 추가되며 EnlargedScreenShots
에 표시됩니다. 여기에 UserControl
여기
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; } }
ListOfScreenShots
에 대한 XAML입니다 방법이다. 그것은 또한 무슨 일이 일어나고 있는지 명확하게 이해해야합니다.
ListOfScreenShots의 XAML :
<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">
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl Name="_listBox" ItemsSource="{Binding ''}">
<!--<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>-->
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Name ="_thumbnailImage" Width="600" VerticalAlignment="Center" Source="{Binding ''}"/>
<Button VerticalAlignment="Center" HorizontalAlignment="Center" Name="_addscreenshot" Content="Select Screenshot" Command="{x:Static support:SelectScreenShots.SelectImageCommand}"
CommandParameter="{Binding ''}" Width="150" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</UserControl>
메인 창 XAML : 뒤에
<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">
<Window.CommandBindings>
<CommandBinding Command="support:SelectScreenShots.SelectImageCommand" Executed="MainWindowCommandBinding_Executed"/>
</Window.CommandBindings>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="367"/>
<RowDefinition Height="167"/>
<RowDefinition Height="33"/>
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="0" Name="_contentPresenter" Content="{Binding ''}"/>
<ContentPresenter Grid.Row="1" Name="_contentPresenter2" Content="{Binding ''}"/>
<StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Name="_OK_Button" Content="OK" Click="_OK_Button_Click" Margin="0,5,5,5" Width="75" Height="23"/>
<Button Name="_Cancel_Button" Content="Cancel" Click="_Cancel_Button_Click" Margin="0,5,5,5" Width="75" Height="23"/>
</StackPanel>
</Grid>
주 창 코드 :
public partial class SelectScreenShots : DXWindow
{
public static readonly RoutedCommand SelectImageCommand = new RoutedCommand();
public static List<BitmapSource> selectedImages = new List<BitmapSource>();
public static List<BitmapSource> screenshots = new List<BitmapSource>();
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<BitmapSource> RenderWindows()
{
var windows = Application.Current.Windows
.OfType<Window>()
.Where(x => x.GetType() != typeof(AskAQuestionDialog) & x.GetType() != typeof(SelectScreenShots));
var bitmaps = new List<BitmapSource>();
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();
}
}
}
,363,210
사용자 컨트롤의 XAML :
이<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">
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<StackPanel Orientation="Horizontal">
<ItemsControl Name="_itemsControl" ItemsSource="{Binding ''}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Name ="_thumbnailImage" HorizontalAlignment="Left" VerticalAlignment="Center" Source="{Binding ''}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
</Grid>
가 크기 조정 및 스크롤 막대 가시성이 제대로 작동하지 않을뿐만까지 계속 다른 일을하지만, 나중에 그 밖으로 작동합니다. 지금 이것은 정말로 나를 괴롭 히고있다.
누구나 분명히 잘못된 것을 볼 수 있습니다. 나는 스택 패널에 모든 것이 싸여 있다는 사실과 관련이 있다고 생각하지만, DataTemplate
안에있는 이미지가 StackPanel
으로 감싸지기 전에는 여전히 작동하지 않습니다. 또한 StackPanel
을 모두 제거하고 WrapPanel
을 사용해 보았습니다.
도움을 주시면 감사하겠습니다. 고맙습니다.
그것은 여기에 무슨 일이 일어나고 있는지에 따라 쉽지 않다 : 난 그냥 여기에 속으로
EnlargedScreenShot ess = new EnlargedScreenShot();
를 이동했다. 'ListOfScreenShots' 무엇입니까? 'UserControl'은 어디에 적용됩니까? – McGarnagle
MainWindowCommandBinding_Executed 안에 e.Parameter에 이미지가 있는지 확인하십시오. – jure
@jure 예 명령 매개 변수가 있습니다. 매개 변수의 출처 인'ListOfScreenshots'에서 xaml을 게시했습니다. 이미지가'UserControl'에 추가되고 있는데, 제대로 표시되지 않습니다. – Adam