让我的UserControl显示它包含控件的背景 [英] Getting my UserControl to display it's containing controls' background

查看:85
本文介绍了让我的UserControl显示它包含控件的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个部署了MVVM,Prism和Unity的WPF应用程序.我正在使用Prism 4.1和Unity 2.0.

我已经创建了Shell,菜单"区域是ContentControl.一个带有阴影的凸起框,背景相当不透明,显示了其包含网格的背景.

I have a WPF application deployed with MVVM, Prism, and Unity. I''m using Prism 4.1 and Unity 2.0.

I have my Shell created and the "menu" area is a ContentControl; a raised box with shadowing and a fairly opaque background showing the background of it''s containing grid.

<ContentControl Name="MenuRegion" c:RegionManager.RegionName="MenuRegion" Margin="12,165,748,12" >
    <ContentControl.Template>
        <ControlTemplate TargetType="ContentControl">
            <Grid>
                <Controls:RoundedBox />
                <ContentPresenter Margin="10,0,10,0" Content="{TemplateBinding Content}" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="HasContent" Value="false">
                    <Setter Property="Visibility" Value="Collapsed" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </ContentControl.Template>
</ContentControl>



我有一个UserControl,无非就是一个包含ListView来显示菜单"内容的网格.

我想要做的是设置ListView的样式,以便它消失"到包含的控件中.我已经在Google上进行了搜索,但是我发现的所有示例都只是针对样式化ListViewItem.我已经看到了一个或两个执行此操作的应用程序示例,但是没有公开底层的XAML.我如何设置ListView的样式,使其本质上变得不可见(除了ListViewItem内容之外)?



I have a UserControl which is nothing more than a grid that contains a ListView to display the "menu" contents.

What I want to do is style the ListView so that it "disappears" into the containing control. I''ve searched on Google but all of the examples I find are more aimed at just styling the ListViewItem. I''ve seen one or two example of application that do this, but do not expose the underlying XAML. How do I style the ListView to become, essentially, invisible except for the ListViewItem contents? Do I have to also style the grid or does it stay out of the visual inheritance path?

推荐答案

我最终要做的(确实)非常简单.最终,他比其他任何人都更加了解语法.

对于我的ListView,我最终使用特定的笔刷实现了定义:

What I ended up doing was (really) quite simple. It ended up being more of understanding syntax more than anything else.

For my ListView I ended up having my definition implemented with specific brushes:

<ListView ItemTemplate="{StaticResource ResourceKey=DisplayInfo}" ItemsSource="{Binding Path=EventList}" Height="568" HorizontalAlignment="Left" VerticalAlignment="Top" Width="201" Margin="1,4,0,0">
    <ListView.BorderBrush>
        <SolidColorBrush />
    </ListView.BorderBrush>
    <ListView.Background>
        <SolidColorBrush Color="#99FFFFFF" Opacity=".8"/>
    </ListView.Background>
</ListView>



而且,正如我在阅读的文章中所指定的那样,使用笔刷分配可以使我实现性能最高.它仍然比衬里容器轻一点,但是它是不透明的,看起来很自然.因此,只需稍作调整即可使我到达最终产品所需的位置. :)还应该为其他读者指出,Grid不会影响可视堆栈.因此,将列表框设置为不透明即可满足我的需要,而无需在网格上进行任何视图设置.



And as specified in an article I read, doing it with a brush assignment gives me the most performant implementation. It still comes out a touch lighter than the backing container, however it is opaque and looks natural. So just a little tweaking should get me where I need to be for the final product. :) It should also be noted for other readers that the Grid stays out of the way as far as the visual stack goes. So setting the listbox opaque gives me what I need without having the screw with any view settings on the Grid.


我认为您需要创建一个透明的listviewItem,如下所示:

I think you need to create a transparent listviewItem like this:

<style targettype="ListBoxItem">
                <style.resources>
                    <solidcolorbrush x:key="{x:Static SystemColors.HighlightBrushKey}" color="Transparent" xmlns:x="#unknown" />
                </style.resources>
            </style>



一旦设置了样式,您将不会(不应该)具有突出显示的颜色.接下来,您可以像这样简单地设置listview的样式:



Once this is styled you wont have (shouldnt have) a highlight color. Next you can simply style the listview like so:

<listbox itemssource="{Binding MenuItems}" background="Transparent" selectionmode="Single">
SelectedItem="{Binding SelectedItem}"></listbox>


这篇关于让我的UserControl显示它包含控件的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆