我以编程方式创建 WPF TabItem 并将其添加到我的 TabControl。
var tabItem = new TabItem { Header = "foo" };
现在我想做类似的事情
var txt1 = new TextBlock { Text = "foo" };
var txt2 = new TextBlock { Text = "bar" };
var tabItem = new TabItem { Header = txt1 + txt2 }; // cannot apply operator + to TextBlock and TextBlock
// Other Idea:
// var tabItem = new TabItem { Header = new TextBlock { Text = "foo" }.Text + new TextBlock { Name = "txt2", Text = "bar" }};
// Maybe I could edit my TextBlock via it's name?
...
txt2.Text = "editedBar"; // have to update the header of tabItem.
这有可能吗?我知道在 XAML 中这不是问题。但是现有的架构迫使我尝试这种方式。