我正在尝试在xaml中创建按钮的动态列表,并具有常见的Command和不同的Content和CommandParameter。我连接了样式和命令。而且我做了动态列表,但是我不知道下一步/
XAML
<ItemsControl ItemsSource="{Binding Permissions}">
<ItemsControl.Template>
<ControlTemplate>
<Button Style="{StaticResource BigButtonStyle}"
Content="{Binding Name}"
Command="{Binding ChangeViewClick}"
CommandParameter="{Binding Name}"/>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
ViewModel
private UserControl content;
public UserControl Content
{
get => content;
private set => SetProperty(ref content, value);
}
public FunctionCommand ChangeViewClick { get; }
ChangeViewClick = new FunctionCommand(ChangeView);
private void ChangeView(object name)
{
Content = (UserControl)Activator.CreateInstance(Type.GetType($"Mistakes.Desktop.Views.{name}Permission"));
}
我想将Content显示为Name的PermissionModel并传递与CommandParameter相同的名称