windows phone 8 listbox grid设置内部元素不透明度为full

时间:2013-11-21 10:52:02

标签: c# wpf xaml windows-phone-7 windows-phone-8

这段代码的问题是我已经将网格的不透明度设置为0.5并且使我的网格框透明(很好),但问题是文本和图像以及复选框应该在完全不透明。如何在不影响内部元素的情况下使网格透明?

尝试:

我在datatemplate中创建了一个stackpanel,并尝试将其放在带有margin属性的网格中,但是无法在列表框的datatemplate中使用grid进行stackpanel。任何解决方案

  <ListBox Grid.Row="1" x:Name="BookCategories" ItemsSource="{Binding}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>                   
                        <toolkit:WrapPanel  ItemHeight="200" ItemWidth="200" Margin="10"/>                 
                </ItemsPanelTemplate>
                </ListBox.ItemsPanel>

                <ListBox.ItemTemplate>
                    <DataTemplate>
                    <Grid Background="#12161e" Opacity="0.5" Tap="Grid_Tap_1"  Margin="10,-5,0,20" Height="200" Width="200">
                        <CheckBox Grid.Row="1"  Margin="145,-15,-15,0" x:Name="Chkcategories" Click="Chkcategories_Click" >
                            <Image Margin="-80,-140,-15,0" Height="20" Width="20" Source="{Binding ElementName=Chkcategories, Path=IsChecked, Converter={StaticResource BoolToImageSource} }"></Image>
                        </CheckBox>                         
                        <Image Width="50" Opacity="100" Height="50" Margin="30,30,0,0" Source="Assets/icons/food.png"></Image>
                            <TextBlock  Margin="40, 80, 0, 0" FontSize="22" Text="{Binding Path=CategoryName}"></TextBlock>

                    </Grid>

                </DataTemplate>
                </ListBox.ItemTemplate>

        </ListBox>

2 个答案:

答案 0 :(得分:2)

如果直接在Grid Opacity = ...设置中设置,则不透明度设置将继承所有子元素。你应该使用这样的不透明度:

<Grid>
<Grid.Background>
    <SolidColorBrush Color="#12161e" Opacity="0.5" />
</Grid.Background>
... content ...
</Grid>

答案 1 :(得分:0)

您必须使用Alpha通道(0-255)。

255(最大)* 0.5(您的不透明度)= 127.5 =&gt; 128 =&gt; 80 hex

<Grid Background="#8012161e" ...