c# - WPF 自定义 TabItem - 控件未显示在 Visual Studio 设计器中

标签 c# wpf visual-studio-2015 custom-controls

我创建了一个自定义 TabItem,里面有一个 DockPanel 和一个 Button。

XAML:

<TabItem
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      mc:Ignorable="d" x:Class="MovieDB.UI.UserControlls.SearchTab" d:DesignWidth="500.038" d:DesignHeight="309.055">

    <DockPanel Background="#FFE5E5E5">
        <Button x:Name="button" Content="Button" Height="100" Width="75" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    </DockPanel>
</TabItem>

C#:

namespace MovieDB.UI.UserControlls
{
    /// <summary>
    /// Interaktionslogik für SearchTab.xaml
    /// </summary>
    public partial class SearchTab : TabItem
    {
        private SearchContainer<SearchMovie> results;

        public SearchTab()
        {
            InitializeComponent();
            this.Header = "Suche";
        }

        public SearchTab(SearchContainer<SearchMovie> results):this()
        {
            this.updateSearch(results);
        }

        public void updateSearch(SearchContainer<SearchMovie> results)
        {
            clear();
            if(results.TotalResults == 0)
            {

            }
            else
            {
                this.results = results;
                Debug.WriteLine("Results: " + results.Results.Count());
            }
        }

        private void clear()
        {

        }
    }
}

如果启动我的程序,则会显示该按钮(屏幕截图 2)。但是按钮和我猜想面板本身并没有出现在 Visual Studio 2015 Designer 中(屏幕截图 1)。

问题出在哪里?

Screenshot Designer Screenshot running Programm

最佳答案

如果将 TabItem 放在 TabControl 中,它工作正常。我认为这就是问题所在。 设计师需要一个导航控件,如 TabControl、Window Page 等。

<TabControl x:Class="CustomControls.tab"
             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"
            mc:Ignorable="d" 
            d:DesignWidth="500.038" d:DesignHeight="309.055">
<TabItem>
    <DockPanel Background="#FFE5E5E5">
        <Button x:Name="button" Content="Button" Height="100" Width="75" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    </DockPanel>
    </TabItem>
</TabControl>

关于c# - WPF 自定义 TabItem - 控件未显示在 Visual Studio 设计器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35164072/

相关文章:

c# - WPF SQLite 查询异常

Javascript 文件未加载到 aspx 中? ASP.NET C#

C#、文本框、.NET

c# - UPDATE子句中的集合列表中的错误。无法解析查询文本

wpf - WPF 中的主细节绑定(bind)

asp.net - 安装 VS 2015 时 Redis session 提供程序中断

c# - 使用带有标志枚举的 ProtoBuf-Net 时出错

c# - 以编程方式更改 ScrollViewer 中的滚动条宽度

c# - DataWindowButton CanExecute 未触发,Catel 4.0

json - tsconfig.json : Build:No inputs were found in config file