给位大神帮帮忙!一个floatlayoutPanel,9个picturebox(3行3列),然后有1000张图片,要把这些图片放进里面去.

时间:2021-05-04 17:42:28
一个floatlayoutPanel,9个picturebox(3行3列),然后有1000张图片,要把这些图片放进里面去.还有可以点击里面图片弹出背景.要把这些图片和其他数据放进里面去.还有可以点击里面图片弹出背景.各位大神有谁能给我意见吗?能帖代码最好了,小白一个,做了很久做不出来 给位大神帮帮忙!一个floatlayoutPanel,9个picturebox(3行3列),然后有1000张图片,要把这些图片放进里面去.给位大神帮帮忙!一个floatlayoutPanel,9个picturebox(3行3列),然后有1000张图片,要把这些图片放进里面去.  

4 个解决方案

#1


给位大神帮帮忙!一个floatlayoutPanel,9个picturebox(3行3列),然后有1000张图片,要把这些图片放进里面去.
就是个自定义列表,然后添加datasources属性.我自己做了个自定义控件,如图.数据是image和序号和名称.
picturebox里面放.Image.    Lable就是序号和名称.现在不知道要怎么样把这组合个控件和datasource绑定,能教教我吗?

#2



using System;
using System.Linq;
using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            string[] animals = new string[] 
            {
                "alligator", "ants", "bear", "bee", "cat", "snail", "snake",
                "cheetah", "cow", "deer", "dolphin", "dragonfly", "spider", "squirrel",
                "duck", "elephant", "frog", "giraffe", "ladybug", "starfish", 
            };
            this.DataContext = animals.Select(x => new My(x)).ToList();
        }
    }
    class My
    {
        public My(string name)
        {
            this.Name = name;
            this.ImageSource = string.Format("http://www.sciencekids.co.nz/images/pictures/animals/{0}.jpg", name);
        }
        public string Name { get; set; }
        public string ImageSource { get; set; }
    }
}



<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow">
    <Window.Resources>
        <DrawingBrush x:Key="circleMask">
            <DrawingBrush.Drawing>
                <GeometryDrawing Brush="White" Geometry="M -1,0 A 1,1 0 1 1 1,0 M -1,0 A 1,1 0 1 0 1,0" />
            </DrawingBrush.Drawing>
        </DrawingBrush>
        <DataTemplate x:Key="my">
            <StackPanel Orientation="Vertical" Margin="0 10 0 10">
                <Image Source="{Binding ImageSource}" Width="200" Height="200" Stretch="Fill" OpacityMask="{StaticResource circleMask}" />
                <TextBlock Text="{Binding Name}" FontSize="16" HorizontalAlignment="Center" />
            </StackPanel>
        </DataTemplate>
        <ItemsPanelTemplate x:Key="threeRowPanel">
            <UniformGrid Columns="3" />
        </ItemsPanelTemplate>
    </Window.Resources>

    <DockPanel>
        <ContentControl ContentTemplate="{StaticResource my}" Content="{Binding ElementName=listbox, Path=SelectedItem}" Height="240" DockPanel.Dock="Bottom" />
        <ListBox Name="listbox" ItemTemplate="{StaticResource my}" ItemsSource="{Binding}" ItemsPanel="{StaticResource threeRowPanel}" DockPanel.Dock="Top" />
    </DockPanel>
</Window>


#3


Mark yi xia

#4


一下子加载1000多涨图片到内存,是不是有点浪费资源啊。
单击弹出一个窗体就能解决你的第二个问题

#1


给位大神帮帮忙!一个floatlayoutPanel,9个picturebox(3行3列),然后有1000张图片,要把这些图片放进里面去.
就是个自定义列表,然后添加datasources属性.我自己做了个自定义控件,如图.数据是image和序号和名称.
picturebox里面放.Image.    Lable就是序号和名称.现在不知道要怎么样把这组合个控件和datasource绑定,能教教我吗?

#2



using System;
using System.Linq;
using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            string[] animals = new string[] 
            {
                "alligator", "ants", "bear", "bee", "cat", "snail", "snake",
                "cheetah", "cow", "deer", "dolphin", "dragonfly", "spider", "squirrel",
                "duck", "elephant", "frog", "giraffe", "ladybug", "starfish", 
            };
            this.DataContext = animals.Select(x => new My(x)).ToList();
        }
    }
    class My
    {
        public My(string name)
        {
            this.Name = name;
            this.ImageSource = string.Format("http://www.sciencekids.co.nz/images/pictures/animals/{0}.jpg", name);
        }
        public string Name { get; set; }
        public string ImageSource { get; set; }
    }
}



<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow">
    <Window.Resources>
        <DrawingBrush x:Key="circleMask">
            <DrawingBrush.Drawing>
                <GeometryDrawing Brush="White" Geometry="M -1,0 A 1,1 0 1 1 1,0 M -1,0 A 1,1 0 1 0 1,0" />
            </DrawingBrush.Drawing>
        </DrawingBrush>
        <DataTemplate x:Key="my">
            <StackPanel Orientation="Vertical" Margin="0 10 0 10">
                <Image Source="{Binding ImageSource}" Width="200" Height="200" Stretch="Fill" OpacityMask="{StaticResource circleMask}" />
                <TextBlock Text="{Binding Name}" FontSize="16" HorizontalAlignment="Center" />
            </StackPanel>
        </DataTemplate>
        <ItemsPanelTemplate x:Key="threeRowPanel">
            <UniformGrid Columns="3" />
        </ItemsPanelTemplate>
    </Window.Resources>

    <DockPanel>
        <ContentControl ContentTemplate="{StaticResource my}" Content="{Binding ElementName=listbox, Path=SelectedItem}" Height="240" DockPanel.Dock="Bottom" />
        <ListBox Name="listbox" ItemTemplate="{StaticResource my}" ItemsSource="{Binding}" ItemsPanel="{StaticResource threeRowPanel}" DockPanel.Dock="Top" />
    </DockPanel>
</Window>


#3


Mark yi xia

#4


一下子加载1000多涨图片到内存,是不是有点浪费资源啊。
单击弹出一个窗体就能解决你的第二个问题