メイン ページを作成し、ユーザー コンポーネントを使用してマスター ページ Web サイトのスタイルを実装しました。ドロップダウン コンボ ボックスを作成して、ユーザーがコンボ ボックスで自分の役割を選択できるようにします。ロジック ステートメントを実行する必要があるときに、xaml 以外の C# コードを使用して別のユーザー コントロールを呼び出すことができることを知っているかもしれません。
このコンボボックスで別のコンポーネントをロードして、1 つのマスター ページを取得しました。
<ComboBox x:Name="cbRole" Height="30" Margin="8,8,8,100" VerticalAlignment="Top" ToolTipService.ToolTip="Please select your role to login" SelectionChanged="cbRole_SelectionChanged">
<ComboBoxItem Content="Admin"/>
<ComboBoxItem Content="Lecturer"/>
<ComboBoxItem Content="Student"/>
</ComboBox>
マスターページは、この行でコンボボックスをロードします
<betata_Views_Sidebar:Sidebar/>
これを行う方法について質問がありました -->
private void cbRole_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int x = cbRole.SelectedIndex;
if (x == 0)
{
<betata_Views_Sidebar:Sidebar_Admin/>
}
else if (x == 1)
{
<betata_Views_Sidebar:Sidebar_Lecturer/>
}
else if (x == 2)
{
<betata_Views_Sidebar:Sidebar_Student/>
}
else
{
...
}
}