我在这里有一个标记:
<UserControl x:Class="NeoClinic.MAS.ConfigurationsList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
mc:Ignorable="d"
x:Name="ConfigControl">
<Grid Style="{StaticResource ContentRoot}">
<!-- TODO: set @SelectedSource -->
<mui:ModernTab x:Name="ModTab" Layout="List" PreviewMouseLeftButtonUp="ModTab_PreviewMouseLeftButtonUp">
<mui:ModernTab.Links >
<!-- TODO: set @Source -->
<mui:Link x:Name="BreedLink" DisplayName="Breeds" Source="/Pages/BreedListV2.xaml" />
<mui:Link x:Name="SpecieLink" DisplayName="Species" Source="/Pages/SpeciesList.xaml" />
</mui:ModernTab.Links>
</mui:ModernTab>
</Grid>
</UserControl>
然后事件:
private void ModTab_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
// iteratively traverse the visual tree
while ((dep != null) &&
!(dep is ListBoxItem) )
{
dep = VisualTreeHelper.GetParent(dep);
}
if (dep == null)
return;
if (dep is ListBoxItem)
{
var x = dep.Equals(SpecieLink); //error here
}
}
那么如何确定我单击了哪个链接,以便我可以在单个链接中加载不同的用户控件,例如
if(what I clicked == Breeds)
{
BreedLink.Source = new Uri("/BreedList.xaml", UriKind.Relative);
}
else if (what I clicked == BreedsDetails)
{
BreedLink.Source = new Uri("/BreedDetails.xaml", UriKind.Relative);
}
还是有另一种更简单的方法来做到这一点,比如标记绑定?