Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 隐藏组合框切换按钮?_Wpf_Xaml - Fatal编程技术网

Wpf 隐藏组合框切换按钮?

Wpf 隐藏组合框切换按钮?,wpf,xaml,Wpf,Xaml,我试图在中创建一个通用的样式,以便设置侧面的切换按钮的可见性。我找不到解决这个问题的具体问题 我在下面创建了这个样式,但它似乎隐藏了项目中的每个组合框,即使我只在可见时设置了触发器 代码:这是我尝试的风格 <Window.Resources> <Style x:Key="ComboBoxToggleStyle" TargetType="{x:Type ToggleButton}"> <Setter Property="Visibility"

我试图在
中创建一个通用的
样式
,以便设置侧面的
切换按钮
的可见性。我找不到解决这个问题的具体问题

我在下面创建了这个
样式
,但它似乎隐藏了项目中的每个
组合框
,即使我只在
可见时设置了触发器

代码:这是我尝试的风格

<Window.Resources>
    <Style x:Key="ComboBoxToggleStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Visibility" Value="{Binding Path=IsVisible, 
                    RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsVisible" Value="True">
                                <Setter Property="Visibility" Value="Hidden" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

任何能为我指明正确方向的帮助都会很好。

您不能设置
IsVisible
属性,因为它没有公共setter。您不能绑定
Setter
属性,因此这将不起作用

您可以将要隐藏其
ToggleButton
的特定组合框的
Style
属性设置为具有缺少
ToggleButton
模板的
Style

<ComboBox Style="{StaticResource styleWithoutToggleButton}" />


ComboBoxToggleStyle的ControlTemplate为空…这意味着ToggleButton没有“外观”。您希望何时以及如何隐藏切换按钮?@mm8,当我在实际组合框XAML中设置
IsVisible=“True”
时,我想禁用切换按钮。IsVisible是您的自定义属性吗?因为无法设置内置的。它是只读的…@mm8,是的,我试图在这里设置它
您不能设置IsVisible属性,因为它没有公共setter。您不能绑定Setter的Value属性,所以这永远不会起作用。好的,我来看看我能做些什么。谢谢你指出了正确的方向。我只是想让你知道我是按照你建议的方式工作的。我没有想到要做两种不同的款式。再次感谢你的帮助。
<ComboBox Style="{StaticResource styleWithoutToggleButton}" />