如何用 XAML 标签替换此 C# 代码?

How to replace this C# code by XAML tags?

我在 WPF 应用程序中有以下 C# 代码。

Style s = new Style();
s.Setters.Add(new Setter(UIElement.VisibilityProperty, Visibility.Collapsed));
this.ItemContainerStyle = s;

this 是对 System.Windows.Controls.TabControl 对象的引用。 谁能帮我用XAML.

写这段代码

看看http://msdn.microsoft.com/en-us/library/system.windows.style%28v=vs.110%29.aspx

应该是这样的:

<Style>
    <Setter Property="Visbility" Value="Collapsed"/>
</Style>

尝试这样的事情:

<Window.Resources>
  <Style x:Key="VisibilityCollapsed" x:Type="TabItem">
      <Setter Property="Visibility" Value="Collapsed" />
  </Style>
</Window.Resources>

<TabControl ItemContainerStyle="{StaticResource VisibilityCollapsed}">
...
</TabControl>

See also MSDN

这对我来说非常有效:

<Window.Resources>
    <Style x:Key="VisibilityCollapsed">
      <Setter Property="UIElement.Visibility" Value="Collapsed" />
    </Style>
</Window.Resources>

<TabControl ItemContainerStyle="{StaticResource VisibilityCollapsed}">
   ......
</TabControl>