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

 

全站熱搜

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