我做了一个主页并使用用户组件来实现主页网站的样式。我制作了一个下拉组合框以允许用户在组合框中选择他们的角色,我是否知道可以在 xaml 之外使用 C# 代码调用另一个用户控件,而我需要做一些逻辑语句。
我有一个母版页,用这个组合框加载另一个组件:
<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
{
...
}
}