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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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 - Fatal编程技术网

Wpf 仅在控件中使用半透明背景

Wpf 仅在控件中使用半透明背景,wpf,Wpf,我想知道是否有可能制作一个具有半透明背景的新模板(例如按钮)?我可以设置背景属性,然后选择我的不透明度,但问题出在这里。。。当我设置背景的不透明度时,添加为setopacity元素内容的每个元素也将是透明的。如何避免它?这个怎么样?这只是一个简单的版本。您必须自己添加触发器等 <Style x:TargetType="Button"> <Setter Property="Template"> <Setter.Value>

我想知道是否有可能制作一个具有半透明背景的新模板(例如按钮)?我可以设置
背景
属性,然后选择我的
不透明度
,但问题出在这里。。。当我设置背景的不透明度时,添加为set
opacity
元素内容的每个元素也将是透明的。如何避免它?

这个怎么样?这只是一个简单的版本。您必须自己添加触发器等

<Style x:TargetType="Button">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate x:TargetType="Button">
                <Border BorderBrush="{TemplateBinding BorderBrush}">
                    <Grid>
                        <ContentPresenter Content="{TemplateBinding Content}"/>
                        <Border Background="{TemplateBinding Background}"/>
                    </Grid>
                </Border>
            <ControlTemplate/>
        </Setter.Value>
    <Setter/>
</Style>


现在,您可以在不影响内容的情况下指定任何背景画笔。

这个怎么样?这只是一个简单的版本。您必须自己添加触发器等

<Style x:TargetType="Button">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate x:TargetType="Button">
                <Border BorderBrush="{TemplateBinding BorderBrush}">
                    <Grid>
                        <ContentPresenter Content="{TemplateBinding Content}"/>
                        <Border Background="{TemplateBinding Background}"/>
                    </Grid>
                </Border>
            <ControlTemplate/>
        </Setter.Value>
    <Setter/>
</Style>

现在,您可以指定任何背景笔刷,而不影响内容