gpt4 book ai didi

c# - BringIntoView 不工作

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:39 25 4
gpt4 key购买 nike

我在事件处理程序后面有这段代码:

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;
}
}
}

XAML 中的 Border 对象之一的示例:

<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>

这行代码:borders[iBorder].BringIntoView(); 好像不行。我所有 Border 对象的颜色都设置正确,但程序显然没有尝试反对这行代码。

为您提供此 Border 对象所在位置的上下文:

\\ 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

最佳答案

BringIntoView(),根据MSDN :

Attempts to bring this element into view, within any scrollable regions it is contained within.

因此它不会选择标签项、展开扩展器等。您需要自己做。

请注意,由于调度程序的优先级队列,内容可能不会在您进行更改(例如选择标签)后立即可用。在这种情况下,您可能希望以较低的优先级发布进入 View 请求:

var localBorderIndex = iBorder; // copy to avoid closure of loop variable
Dispatcher.InvokeAsync(() => borders[localBorderIndex].BringIntoView(),
DispatcherPriority.Background);

关于c# - BringIntoView 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38532196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com