码迷,mamicode.com
首页 > Windows程序 > 详细

WPF布局间的切换方法

时间:2016-10-20 23:55:40      阅读:434      评论:0      收藏:0      [点我收藏+]

标签:

效果图,两种效果间的切换

技术分享

 

技术分享

 

xaml:

<StackPanel>
        <Button Content="wrap布局" Click="Button_Click" Width="100"></Button>
        <Button Content="stack布局" Click="Button_Click_1" Width="100"></Button>
        <ListBox Name="lb" HorizontalContentAlignment="Stretch">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border BorderThickness="1" BorderBrush="Red">
                        <TextBlock Text="{Binding }"></TextBlock>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </StackPanel>

后台事件:

 public MainWindow()
        {
            InitializeComponent();
            List<string> list = new List<string>();
            for (int i = 0; i < 10; i++)
            {
                list.Add("item" + i);
            }
            lb.ItemsSource = list;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            lb.ItemsPanel = this.FindResource("one") as ItemsPanelTemplate;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            lb.ItemsPanel = this.FindResource("two") as ItemsPanelTemplate;
        }
    }

 

WPF布局间的切换方法

标签:

原文地址:http://www.cnblogs.com/lunawzh/p/5982705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!