Arbeit habe ich diesen Code hinter Ereignishandler:BringIntoView nicht
private void comboActiveStudentAssignmentType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
List<Border> borders = new List<Border>();
// The list of border (focus rectangles) matches the combo of assignment types
borders.Add(borderBibleReadingMain);
borders.Add(borderBibleReadingClass1);
borders.Add(borderBibleReadingClass2);
borders.Add(borderMainHallStudent1);
borders.Add(borderMainHallAssistant1);
borders.Add(borderMainHallStudent2);
borders.Add(borderMainHallAssistant2);
borders.Add(borderMainHallStudent3);
borders.Add(borderMainHallAssistant3);
borders.Add(borderClass1Student1);
borders.Add(borderClass1Assistant1);
borders.Add(borderClass1Student2);
borders.Add(borderClass1Assistant2);
borders.Add(borderClass1Student3);
borders.Add(borderClass1Assistant3);
borders.Add(borderClass2Student1);
borders.Add(borderClass2Assistant1);
borders.Add(borderClass2Student2);
borders.Add(borderClass2Assistant2);
borders.Add(borderClass2Student3);
borders.Add(borderClass2Assistant3);
// Loop through the borders
for(int iBorder = 0; iBorder < borders.Count; iBorder++)
{
// Is this border the active student assignment?
if (comboActiveStudentAssignmentType.SelectedIndex == iBorder)
{
// Yes, so use a red brush for the background
borders[iBorder].BorderBrush = Brushes.Red;
// Now we must ensure the correct tab item is visible
if(iBorder >= 0 && iBorder <= 2)
{
expandTFGW.IsExpanded = true;
if (iBorder == 0)
tabTFGWReadingMainHall.IsSelected = true;
else if (iBorder == 1)
tabTFGWReadingClass1.IsSelected = true;
else if (iBorder == 2)
tabTFGWReadingClass2.IsSelected = true;
}
else if (iBorder >= 3 && iBorder <= 8)
{
expandAYFM.IsExpanded = true;
tabAYFMStudentsMainHall.IsSelected = true;
if (iBorder == 3 || iBorder == 4)
tabMainHallItem1.IsSelected = true;
else if (iBorder == 5 || iBorder == 6)
tabMainHallItem2.IsSelected = true;
else if (iBorder == 7 || iBorder == 8)
tabMainHallItem3.IsSelected = true;
}
else if (iBorder >= 9 && iBorder <= 14)
{
expandAYFM.IsExpanded = true;
tabAYFMStudentsClass1.IsSelected = true;
if (iBorder == 9 || iBorder == 10)
tabClass1Item1.IsSelected = true;
else if (iBorder == 11 || iBorder == 12)
tabClass1Item2.IsSelected = true;
else if (iBorder == 13 || iBorder == 14)
tabClass1Item3.IsSelected = true;
}
else if (iBorder >= 15)
{
expandAYFM.IsExpanded = true;
tabAYFMStudentsClass2.IsSelected = true;
if (iBorder == 15 || iBorder == 16)
tabClass2Item1.IsSelected = true;
else if (iBorder == 17 || iBorder == 18)
tabClass2Item2.IsSelected = true;
else if (iBorder == 19 || iBorder == 20)
tabClass2Item3.IsSelected = true;
}
borders[iBorder].BringIntoView();
}
else
{
// No, so set the background to transparent so we can't see it.
borders[iBorder].BorderBrush = Brushes.Transparent;
}
}
}
}
Ein Beispiel für eine der Border
Objekte in XAML:
<Border x:Uid="borderMainHallStudent1" x:Name="borderMainHallStudent1" BorderThickness="5">
<Border.Style>
<Style x:Uid="Style_30" TargetType="Border">
<Setter x:Uid="Setter_76" Property="BorderBrush" Value="Transparent"/>
<Style.Triggers>
<DataTrigger x:Uid="DataTrigger_29" Binding="{Binding SelectedItem, ElementName=comboActiveStudentAssignmentType}"
Value="{x:Static StudentInfoEnums:StudentAssignmentType.Student1Main}">
<Setter x:Uid="Setter_77" Property="BorderBrush" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<StackPanel x:Uid="StackPanel_35">
<Label x:Uid="Label_38" Content="Student:"/>
<Grid x:Uid="Grid_15">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Uid="ColumnDefinition_34" Width="*"/>
<ColumnDefinition x:Uid="ColumnDefinition_35" Width="auto"/>
</Grid.ColumnDefinitions>
<TextBox x:Uid="textMainHallStudent1" x:Name="textMainHallStudent1"
Text="{Binding MainHallStudent1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="False" Grid.Column="0" Margin="2" />
<Button x:Uid="buttonMainHallStudent1" x:Name="buttonMainHallStudent1" Grid.Column="1" Background="Transparent"
DataContext="{Binding DataContext, ElementName=oclmEditor}"
Command="{Binding ApplicationCommand}"
CommandParameter="Student1Main">
<Image x:Uid="Image_17" Source="Images/AssignmentTypeStudent16.png" Margin="2"/>
</Button>
</Grid>
<Label x:Uid="Label_39" Content="Study:"/>
<ComboBox x:Uid="ComboBox_9" DataContext="{Binding DataContext, ElementName=oclmEditor}"
ItemsSource="{Binding StudentStudyPointsList}"
ItemContainerStyle="{StaticResource StudyPointComboBoxStyle}"
ItemTemplate="{StaticResource StudyPointComboItem}"
Validation.ErrorTemplate="{StaticResource StudyPointValidationTemplate}"
Tag="{Binding Meeting.MainHallStudent1, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
SelectedValue="{Binding Meeting.MainHallStudent1StudyNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedValuePath="Number"/>
</StackPanel>
</Border>
Diese Codezeile: borders[iBorder].BringIntoView();
Es scheint nicht zu funktionieren. Die Farben aller meiner Border-Objekte sind richtig eingestellt, aber das Programm macht offensichtlich keinen Versuch, diese Codezeile zu widerlegen.
Um Ihnen den Kontext, wo dieses Border
Objekt vorhanden ist:
\\ Main Window
\\ScrollView
\\ Expander
\\Tab Control
\\Tab Item
\\Border 1
\\Contents
\\Border 2
\\Contents
\\ Expander
\\Tab Control
\\Tab Item
\\Border 1
\\Contents
\\Border 2
\\Contents
Noch eine Beratung, die auf Ihre Frage nicht verwandt ist - die Art und Weisen Sie Ihre UI Aufbau ist sehr un-WPF- ish. Sie sollten in Datenbindungssammlungen suchen. Es könnte Ihnen viel repetitiven Code ersparen. –
@EliArbel Ich verwende Datenbindungssammlungen. Dies wird im XAML-Snippet angezeigt. Immer noch lernen. Dieser spezifische Code ist nur für die Benutzeroberfläche gedacht. –