首页 > 其他分享 >WPF ListBox acts image container, ItemTemplate,DataTemplate,

WPF ListBox acts image container, ItemTemplate,DataTemplate,

时间:2024-05-17 19:18:32浏览次数:23  
标签:ItemTemplate container Windows image System zoomLevel imgsCollection using publi

<Window x:Class="WpfApp100.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp100" WindowState="Maximized"
        mc:Ignorable="d"  
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <ListBox x:Name="lbx" 
                 ItemsSource="{Binding ImgsCollection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                 BorderBrush="Blue" BorderThickness="3" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <Image Source="{Binding Content,RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Stretch="Uniform"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.ComponentModel;

namespace WpfApp100
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public MainWindow()
        {
            Color color = (Color)ColorConverter.ConvertFromString("#FFA500");
            InitializeComponent();
            this.DataContext = this;
            FillImgList();
            
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler?.Invoke(this, new PropertyChangedEventArgs(propName));
            }
        }

        List<string> imgsCollection;
        public List<string> ImgsCollection
        {
            get
            {
                return imgsCollection;
            }
            set
            {
                if (value != imgsCollection)
                {
                    imgsCollection = value;
                    OnPropertyChanged(nameof(ImgsCollection));
                }
            }
        }

        private double zoomLevel = 1;
        public double ZoomLevel
        {
            get
            {
                return zoomLevel;
            }
            set
            {
                if (value != zoomLevel)
                {
                    zoomLevel = value;
                    OnPropertyChanged(nameof(ZoomLevel));
                }
            }
        }

        void FillImgList()
        {
            string str = @"..\..\Images";
            string fullDir = System.IO.Path.GetFullPath(str);
            if (Directory.Exists(fullDir))
            {
                var imgs = Directory.GetFiles(fullDir, "*", SearchOption.AllDirectories);
                ImgsCollection = new List<string>(imgs);
            }
        }  
    }
}

 

 

 

标签:ItemTemplate,container,Windows,image,System,zoomLevel,imgsCollection,using,publi
From: https://www.cnblogs.com/Fred1987/p/18198446

相关文章

  • k8s安装网络组件calico报错Init:ImagePullBackOff
    问题:安装网络组件calico报错Init:ImagePullBackOff[root@k8s-master15:33:08~/kubernets]#kubectlgetpods-nkube-systemNAMEREADYSTATUSRESTARTSAGEcalico-kube-controllers......
  • 使用 JS 实现在浏览器控制台打印图片 console.image()
    在前端开发过程中,调试的时候,我门会使用console.log等方式查看数据。但对于图片来说,仅靠展示的数据与结构,是无法想象出图片最终呈现的样子的。虽然我们可以把图片数据通过img标签展示到页面上,或将图片下载下来进行预览。但这样的调试过程实在是复杂,何不实现一个console.image......
  • docker客户端升级版本之后pull镜像报错Docker Image Format v1 and Docker Image mani
    故障现象,把docker从24版本升级至26版本之后从客户端pullnfs-client-provisioner镜像时报错报错信息如下#dockerpullquay.io/external_storage/nfs-client-provisioner:latestlatest:Pullingfromexternal_storage/nfs-client-provisioner[DEPRECATIONNOTICE]DockerIm......
  • tui-image-editor中跨域问题
    如何安装tui-image-editor等就不再赘述,参考这篇博客即可,https://blog.csdn.net/weixin_44867717/article/details/128212251简单版参考:https://blog.csdn.net/Bonsoir777/article/details/134153807官网:https://ui.toast.com/tui-image-editor 下面说说我碰到的问题,跨域......
  • updateContainer
    updateContainer是React源码中负责更新容器的函数之一。初始化更新时调用就是该方法。这个函数位于React源码中的ReactFiberReconciler.js文件中,下面是对updateContainer函数的分析:functionupdateContainer(element:ReactNodeList,container:OpaqueRoot,pa......
  • Adding Drivers into VMWare ESXi Installation Image
    ThestandardESXiISOimagedoesn’tsupportmostdesktopNICadapters.ToinstallESXionsuchacomputer,youwillneedtoinjectthedriversforyournetworkadapterintoyourESXiinstallationimageLet’sseehowtoaddthedrivertotheVMwareESXi6.......
  • WPF Canvas在Image 图像上绘图,自适应缩放.
    效果如图  实现了绘图,自适应缩放核心代码如下<Window.InputBindings><KeyBindingKey="Z"Modifiers="Ctrl"Command="{BindingUndoCommand}"/></Window.InputBindings><i:Interaction.Triggers>......
  • Lossless Recompression of JPEG Images Using Transform Domain Intra Prediction
    目录简介引入文章贡献对DCT系数残差进行编码比对原始DCT系数进行编码更有利于压缩模型框架简介\(\quad\)JPEG图像编码格式由于其简单高效在各种设备和网站上被广泛使用,但JPEG与性能与最先进的编码方法相差甚远。如果能对这些JPEG图像再压缩,将会缩减储存成本。该文章提出了......
  • 【container】【docker-compose】【mysql】【redis】【rabbit mq】【mongo】【elastic
    @目录写在前面mysqlredisrabbitmqmongoelasticsearch单节点多节点参考资料dockerkuberneteshelmk3s写在前面相关博文个人博客首页免责声明:仅供学习交流使用!开源框架可能存在的风险和相关后果将完全由用户自行承担,本人不承担任何法律责任。mysqlversion:'3'services:......
  • 2024CVPR_Low-light Image Enhancement via CLIP-Fourier Guided Wavelet Diffusion(C
    一、Motivation1、单模态监督问题:大多数方法往往只考虑从图像层面监督增强过程,而忽略了图像的详细重建和多模态语义对特征空间的指导作用。这种单模态监督导致不确定区域的次优重建和较差的局部结构,导致视觉结果不理想的出现。------》扩散模型缺乏有效性约束,容易出现多种生成效......