gpt4 book ai didi

uwp - 我正在使用 UWP winUI,我尝试动态切换 tabView 选项卡上的内容但失败

转载 作者:行者123 更新时间:2023-12-04 10:08:50 26 4
gpt4 key购买 nike

HI 再次寻求帮助;我提前道歉我已经用谷歌搜索死了,我有一个 tabView,当一个选项卡被点击时,我加载了一个页面,问题是我第一次点击任何选项卡时,内容没有加载,只有当我第二次单击任何选项卡,每个选项卡都会加载正确的内容以清除我单击选项卡时有一个页面我希望页面加载 - 我已经在这里设置了我的方法的副本 https://pastebin.com/NDA1kwb0 Meeeow “可能会或可能不会”使用原始方法帮助我 - 任何帮助将不胜感激,我将继续尝试在此期间找到解决方案;非常感谢您的时间

private void TabView_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var tag = ExtractTag(sender);
var frame = new Frame();

switch (tag)
{
case "General":
frame.Navigate(typeof(GeneralTabView), null, new DrillInNavigationTransitionInfo());
break;
case "ProsAndCons":
frame.Navigate(typeof(ProsAndConsTabView), null, new DrillInNavigationTransitionInfo());
break;
case "ActionPoints":
frame.Navigate(typeof(ActionPointsTabView), null, new DrillInNavigationTransitionInfo());
break;
case "MoodWall":
frame.Navigate(typeof(MoodWallTabView), null, new DrillInNavigationTransitionInfo());
break;
case "Research":
frame.Navigate(typeof(ResearchTabView), null, new DrillInNavigationTransitionInfo());
break;
case "Notes":
frame.Navigate(typeof(NotesTabView), null, new DrillInNavigationTransitionInfo());
break;
case "Export":
frame.Navigate(typeof(ExportTabView),null, new DrillInNavigationTransitionInfo());
break;
}

var target = ExtractTabItem(sender);
target.Content = frame;


}

private static TabViewItem ExtractTabItem(object sender)
{
var temp = (TabView) sender;
var target = (TabViewItem) temp.SelectedItem;
return target;
}

private static string ExtractTag(object sender)
{
var temp = (TabView) sender;
var target = (TabViewItem) temp.SelectedItem;
var tag = target.Tag;
return (string)tag;
}

最佳答案

I have a tabView and when a tab is clicked I load a page the issue is that the first time I click any of the tabs the content doesn’t load, it is only when I click any of the tabs a second time that the right content.



好问题,这种行为很奇怪,请随时在 WinUI github issue box 中发布。一般来说,我们经常初始 TabViewItemTabView加载事件。所以我们的 解决方法 设置了 TabViewItem.Content作为加载事件中的框架,和 NavigateOnSelectionChanged事件。
private void MyTabView_Loaded(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 3; i++)
{
(sender as TabView).TabItems.Add(CreateNewTab(i));
}

}
private TabViewItem CreateNewTab(int index)
{
TabViewItem newItem = new TabViewItem();
newItem.Header = $"Document {index}";
newItem.IconSource = new Microsoft.UI.Xaml.Controls.SymbolIconSource() { Symbol = Symbol.Document };
newItem.Tag = $"Document{index}";
Frame frame = new Frame();
newItem.Content = frame;
return newItem;
}

private void MyTabView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var tag = ExtractTag(sender);
var target = ExtractTabItem(sender);
var frame = target.Content as Frame;

switch (tag)
{
case "Document1":
frame.Navigate(typeof(TestPAge));
break;

}
}

关于uwp - 我正在使用 UWP winUI,我尝试动态切换 tabView 选项卡上的内容但失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61438601/

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