2015-11-16 116 views
0

我使用WPF(c#)窗體與背景圖像(背景圖像刷)。使窗體半透明,以查看窗體的背景圖像

我要讓所有的UI元素(按鈕,標題,文本框)...所以他們不完全覆蓋的圖像,

但背景圖像仍然可見(不變成半透明半透明)

我想我們可以做到這一點,而不必設置UI元素的所有不透明值。

+0

謝謝你的幫助,我看到 – mtrcol

回答

1

也許這可以幫助

<Window.Resources> 
     <Style x:Key="transparentControls" TargetType="Button"> 
      <Setter Property="Opacity" Value="0.1"/> 
      <Setter Property="Background" Value="Green"/> 
     </Style> 
    </Window.Resources> 
    <Grid> 
     <Grid.Background> 
      <ImageBrush ImageSource="MyImage.jpg"/> 
     </Grid.Background> 
     <Button Height="24" Width="100" Style="{StaticResource transparentControls}" VerticalAlignment="Top" Content="Hey"/> 
     <Button Height="24" Width="100" Style="{StaticResource transparentControls}" Content="There"/> 
     <Button Height="24" Width="100" Style="{StaticResource transparentControls}" VerticalAlignment="Bottom" Content="Click Me"/> 
    </Grid> 
+0

非常感謝你,我會嘗試它 – mtrcol

0

只要嘗試將所有UI元素放置在Canvas或Grid中並設置該父元素的不透明度即可。

就像是:

<Canvas Opacity="1"> 
     <Button Width="100" Height="100"></Button> 
</Canvas> 

我希望這是你的意思。

+0

非常感謝你,我就再 – mtrcol

+0

感謝嘗試它,它就像一個魅力:)你讓我很快樂 – mtrcol

+0

你歡迎! :)你能將這個答案標記爲接受嗎? – FKutsche