• WPF ListBox 属性绑定


    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Reflection;

    using System.Windows.Media;

     

    namespace Quietwalk

    {

        public class NamedBrush

        {

            static NamedBrush[] nbrushes;

     

            Brush brush;

            public Brush Brush

            {

                get { return brush; }

            }

     

            string name;

            public string Name

            {

                get

                {

                    string strSpace = name[0].ToString();

                    for (int i = 1; i < name.Length; i++)

                    {

                        strSpace += (char.IsUpper(name[i]) ? " " : "") + name[i].ToString();

                    }

                    return strSpace;

                }

            }

     

            private NamedBrush(string str, Brush brush)

            {

                this.name = str;

                this.brush = brush;

            }

     

            static NamedBrush()

            {

                PropertyInfo[] props = typeof(Brushes).GetProperties();

                nbrushes = new NamedBrush[props.Length];

     

                for (int i = 0; i < props.Length; i++)

                {

                    nbrushes[i] = new NamedBrush(props[i].Name,(Brush)props[i].GetValue(null, null));

                }

            }

     

            public static NamedBrush[] All

            {

                get { return nbrushes; }

            }

     

            public override string ToString()

            {

                return name;

            }

        }

    }

    <ListBox Name="lsBoxNamedBrush" Grid.Row="0" Grid.Column="1"  Grid.RowSpan="10"

                     VerticalAlignment="Center" HorizontalAlignment="Left"

                     SelectedValuePath="Brush" DisplayMemberPath="Name"

                     FontSize="17" Width="200">

               

    </ListBox>

     

     private void Window_Loaded(object sender, RoutedEventArgs e)

            {

           

                this.lsBoxNamedBrush.ItemsSource = Quietwalk.NamedBrush.All;

     

                //Bind SelectedValue of ListBox to this.Background, here the this is the window.

                this.lsBoxNamedBrush.SetBinding(ListBox.SelectedValueProperty, "Background");

                this.lsBoxNamedBrush.DataContext = this;

            }

     

  • 相关阅读:
    使用Dundas控件在web应用上展现多维数据集
    silverlight for olap version milestone 07 updated!
    版本管理客户端工具
    多维数据集数据聚合性能笔记
    关于生成一个随机数组
    Silverlight Dashboards and gauges from codeplex
    在Silverlight下用Visifire显示多维数据集中的数据
    用所能用
    在Vista配置SSAS通过HTTP远程连接的方法.
    手术日记
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2440497.html
Copyright © 2020-2023  润新知