WPF-学习 解决方案集锦

最近一直在做WPF项目,由于从Winform 转WPF开发比较不简单,所以很多用法都忘了,在这做下笔记,也是个解决方案的集合。其中很多的解决方案是引用很多别人的网址。由于还在学习中,会不定时的更新。

1.WPF学习之页面布局(Layout with Panel)

  http://www.cnblogs.com/lxy131/archive/2010/08/23/1806681.html

2.WPF中 DataGrid的样式交替显示内容居中

  http://hi.baidu.com/duduxihaha/item/a0f65027369e6f5cc28d594a

3.wpf 添加滚动条

  http://blog.csdn.net/withdreams/article/details/7506062

4.WPF 隐藏控件 不占用控件

  控件.Visibility = Visibility.Collapsed;

5.获得DataGrid中的某一行或者某一个单元格

   http://blog.csdn.net/cool_time/article/details/6651997

6.绑定图片路径

  <Image Name="img1" Width="16" Height="16"  Source="pack://application:,,,/Images/delete.png"></Image>

    PS:Source="pack://application:,,,/Images/delete.png" 是重点!

7.找到循环模版中放置的控件 获取值

  

   DataGridTemplateColumn templeColumn1 = ListProgramKHQXQ.Columns[1] as DataGridTemplateColumn;
            FrameworkElement fwElement1 = ListProgramKHQXQ.Columns[1].GetCellContent(ListProgramKHQXQ.Items[0]);
            TextBox txt1 = templeColumn1.CellTemplate.FindName("txtCQXQ", fwElement1) as TextBox;
            if (txt1 != null)
            {
                proInfo.ColumnRequire = txt1.Text;
            }

为了详细说明 上图一张

    

8.WPF ComboBox 绑定值

  前台:
 <ComboBox Name="combobox" Width="120" Height="30"/>
后台:
public test5()
        {
            InitializeComponent();

            Dictionary<int, string> mydic = new Dictionary<int, string>()
            {
                {1,"a"},
                {2,"b"},
                {3,"c"}
            };
            combobox.ItemsSource = mydic;
            combobox.SelectedValuePath = "Key";
            combobox.DisplayMemberPath = "Value";
        }

PS: ItemsSource 指定comboBox的数据源,可以是字典,list等任何形式的数据集合
      SelectedValuePath 表示每个item的的实际值,DisplayMemberPath 表示每个item的显示值

posted @ 2013-01-05 17:21  Ruicky  阅读(308)  评论(0编辑  收藏  举报