如何在 WPF 中的 Expander 中隐藏切换按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22655435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 11:20:26  来源:igfitidea点击:

How to hide toggle button from Expander in WPF

wpfwindows

提问by nayas_sub3431732

I want to hide the toggle button in Expander as I am new to WPF.

我想隐藏 Expander 中的切换按钮,因为我是 WPF 的新手。

Expander is inside a datagrid template.

扩展器位于数据网格模板内。

here is the code

这是代码

<DataTemplate >
  <StackPanel >

    <Expander  Margin="0,0,0,0"  Width="Auto" Expanded="Expander_Expanded" Collapsed="Expander_Collapsed" PreviewGotKeyboardFocus="Expander_PreviewGotKeyboardFocus" >

      <Expander.Header>
        <Border x:Name="brdr_header" Padding="0" BorderThickness="0,0,0,1" BorderBrush="Black"   CornerRadius="0">

          <Grid x:Name="InnerData" Width="Auto" >
            <Grid.RowDefinitions>
              <RowDefinition  />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>

采纳答案by Tan

In the "Designer" view in visual studio you can

在 Visual Studio 的“设计器”视图中,您可以

right click on the expander -> Edit Template -> Edit a Copy

右键单击扩展器 -> 编辑模板 -> 编辑副本

Then choose were to put the style. And remove the toggle button and its triggers in the template. Done!

然后选择要放的样式。并删除模板中的切换按钮及其触发器。完毕!

You can also restyle it if you want to,.

如果你愿意,你也可以重新设计它。

回答by Max Mazur

You could retemplate the control, or follow thisexample where you get the Templated Child of the control, and can manipulate it from there :)

您可以重新模板化控件,或按照示例获取控件的模板化子项,并可以从那里对其进行操作:)

Hope that helps :)

希望有帮助:)

回答by Mighty Badaboom

You can get the original style using Expression Blend (if you don't have a key use the trial version). If you got the style you can do anything you want to change the view; e.g. removing the toggle button.

您可以使用 Expression Blend 获得原始样式(如果您没有密钥,请使用试用版)。如果你有风格,你可以做任何你想做的事情来改变视图;例如删除切换按钮。