根據列表框的選擇,哪種做法是最佳方法來更換內容?想想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