根据列表框的选择,哪种做法是最佳方法来更换内容?想想win7的控制面板在左边的链接是如何工作的 - 这就是我想要实现的。交换主要应用程序内容
到目前为止,我已经设置了代码,但由于某种原因,我无法将其实际工作(大概我错误地进行了绑定),我相信这可能不是最好的也可以采用。
<Window x:Class="ControlCenter.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ControlTemplate x:Key="workspace_1" x:Name="Workspace_1">
<StackPanel>
<Button>Test</Button>
<Button>Link to Workspace 2</Button>
<Button>Random function 3</Button>
</StackPanel>
</ControlTemplate>
<ControlTemplate x:Key="workspace_2" x:Name="Workspace_2">
<StackPanel>
<Button>Test 2</Button>
<TextBlock>Some random text</TextBlock>
<Button>Placeholder</Button>
</StackPanel>
</ControlTemplate>
<ControlTemplate x:Key="workspace_3" x:Name="Workspace_3">
<Border Background="Black" />
</ControlTemplate>
</Window.Resources>
<Grid>
<DockPanel>
<ListBox Name="lst_workspaces" Width="150">
<ListBoxItem Content="{DynamicResource ResourceKey=workspace_1}" />
<ListBoxItem Content="{DynamicResource ResourceKey=workspace_2}" />
<ListBoxItem Content="{DynamicResource ResourceKey=workspace_3}" />
</ListBox>
<ContentControl Template="{Binding ElementName=lst_workspaces, Path=SelectedItem.Value}">
</ContentControl>
</DockPanel>
</Grid>
有什么建议?
它**将**非常感激,如果你因为你没有指出我犯的错误,所以给了我**的任何**反馈**。除此之外,我**已经**来这里要求**答案**。问题不够清楚吗?它不够简洁吗? – Johnny