最も簡単な方法これは、動的リストのItemsControlを使用して、そのItemsPanelTemplateをオンザフライで変更することです。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow"
Height="350"
Width="200">
<Window.Resources>
<ItemsPanelTemplate x:Key="wrapPanelTemplate">
<WrapPanel />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="stackPanelTemplate">
<StackPanel />
</ItemsPanelTemplate>
</Window.Resources>
<StackPanel>
<ItemsControl x:Name="itemsControl"
ItemsPanel="{StaticResource wrapPanelTemplate}">
<ListBoxItem Content="TESTTEST " />
<ListBoxItem Content="TESTTEST " />
<ListBoxItem Content="TESTTEST " />
<ListBoxItem Content="TESTTEST " />
</ItemsControl>
<Button Click="Button_Click" Content="Change Template Button"/>
</StackPanel>
MainWindow.xaml.cs:
namespace WpfApplication1
{
public partial class MainWindow : Window
{
ItemsPanelTemplate stackPanelTemp;
public MainWindow()
{
InitializeComponent();
stackPanelTemp = (ItemsPanelTemplate)(this.FindResource("stackPanelTemplate"));
}
private void Button_Click(object sender, RoutedEventArgs e)
{
itemsControl.ItemsPanel = stackPanelTemp;
}
}
}
・ホープ、このことができますここで完全に動作するコードは、私だけで作られた...
MainWindow.xamlです!
ありがとうございます!一度に1つのラベルだけにするにはどうすればいいですか? – Lucas
MVVMパターンをアプリケーションで使用していますか? –
ええ、Caliburn.Microの助けを借りてMVVMを使用しています。 – Lucas