阅读 101

WPF ContentTemplate Demo

 

 


    
        
        
            
                
                    
                    
                        
                
            
        
        
            
                
                    
                    
                        
                    
                        
                
            
        
    
    
        
            
            

        
    

  

using System;
using System.Collections.Generic;
using System.Globalization;
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.Shapes;

namespace WpfDemo
{
    /// 
    /// ContentTemplateDemo.xaml 的互動邏輯
    /// 
    public partial class ContentTemplateDemo : Window
    {
        public ContentTemplateDemo()
        {
            InitializeComponent();

            List list = new List {
                new carView() { logimg="w1", carimg="h1", carproducter="宝马", carname="宝马730L", year=2001, topspeed=300 },
                new carView() { logimg="w2", carimg="h2", carproducter="布加迪", carname="布加迪333", year=2011, topspeed=400 },
                new carView() { logimg="w3", carimg="h3", carproducter="劳斯莱斯", carname="幻影666", year=2021, topspeed=500 }
            };
            this.listBox.ItemsSource = list;

            this.listBox.SelectedIndex = 0;
        }
    }
    public class carListItemView
    {
        public int year { get; set; }
    }
    public class carView
    {
        public string carimg { get; set; }
        public int year { get; set; }
        public string carname { get; set; }
        public int topspeed { get; set; }
        public string logimg { get; set; }
        public string carproducter { get; set; }
    }
    public class carImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string uri = string.Format(@"\pic\{0}.jpeg", value);
            // var map = new BitmapImage(new Uri(uri, UriKind.Relative));
            return uri;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

}

  

原文:https://www.cnblogs.com/JerryZhang320/p/15178296.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐