首页 > Windows开发 > 详细

WPF布局间的切换方法

时间:2016-10-20 23:55:07      阅读:521      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!