0

我有点困惑为什么这不起作用,因为我让它在原型中工作,我认为唯一的大区别是我使用自定义 TabItem 和 UserControl 而不是默认的。我正在尝试获取在选项卡窗口中居中的用户控件,但它似乎左对齐。

您将此方法交给您要使用的用户控件,然后将其格式化并将其粘贴在选项卡控件中。在我之前做的测试解决方案中,将滚动的水平和垂直对齐设置为拉伸修复了这个问题,但在这种情况下它不起作用。是否有其他设置或其他地方可以覆盖它?

public void CreateNewTab(UserControlGeneric new_user_control, string tab_header)
    {
        //TabItem tab = new TabItem();
        TabItemIndexed tab = new TabItemIndexed();
        //The scrollviewer is created/setup to make sure the usercontrol gets scroll bars if the window if ever made smaller than the usercontrol
        ScrollViewer scroll = new ScrollViewer();

        //How you programatically set a scrollviewer's height and width to be "Auto"
        scroll.Height = Double.NaN;
        scroll.Width = Double.NaN;

        scroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
        scroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
        scroll.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
        scroll.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;

        scroll.Content = new_user_control;
        tab.Content = scroll;
        tab.Header = tab_header;

        //If there aren't any tabs, then hide the "No Workspaces Open" notice (Since we're adding a tab)
        if (!tabControl_main.HasItems) label_no_workspaces_open.Visibility = System.Windows.Visibility.Hidden;

        tabControl_main.Items.Add(tab);
        tabControl_main.SelectedItem = tab;

    }
4

0 回答 0