FrameworkElementFactory wrapElement = new FrameworkElementFactory(typeof(WrapPanel));
            ItemsPanelTemplate itemPanelDataTemplate = new ItemsPanelTemplate(wrapElement);
            itemPanelDataTemplate.VisualTree = wrapElement;


            myListbox = new ListBox()
            {
                Opacity = 1,
                Visibility = System.Windows.Visibility.Visible,
                Height = double.NaN,
                Width = double.NaN,
                ItemsPanel = itemPanelDataTemplate,
                Background = null,
                Foreground = null,
                BorderBrush = null,
                VerticalAlignment = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(0, 0, 30, 0)
            };



參考資料:http://social.msdn.microsoft.com/Forums/en-US/f93be7cd-3654-497f-ac80-c57b2555fbfd/how-to-define-a-datatemplate-in-c-code

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 小賢 的頭像
    小賢

    小賢的部落格

    小賢 發表在 痞客邦 留言(0) 人氣()