, the switch between the two effects
Xaml:
<StackPanel> <button content="Wrap Layout"click="Button_Click"Width=" -"></Button> <button content="Stack Layout"click="Button_click_1"Width=" -"></Button> <listbox name="lb"Horizontalcontentalignment="Stretch"> <ListBox.ItemTemplate> <DataTemplate> <border borderthick ness="1"Borderbrush="Red"> <textblock text="{Binding}"></TextBlock> </Border> </DataTemplate> </listbox.ite Mtemplate> </ListBox> </StackPanel>
Background events:
PublicMainWindow () {InitializeComponent (); List<string> list =Newlist<string>(); for(inti =0; I <Ten; i++) {list. ADD ("Item"+i); } lb. ItemsSource=list; } Private voidButton_Click (Objectsender, RoutedEventArgs e) {lb. Itemspanel= This. FindResource (" One") asitemspaneltemplate; } Private voidButton_click_1 (Objectsender, RoutedEventArgs e) {lb. Itemspanel= This. FindResource (" Both") asitemspaneltemplate; } }
How to switch between WPF layouts