Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.

HTML
<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>


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?
Posted
Comments
db7uk 31-May-12 15:10pm    
Firstly, Great to see another Prism user. Love the framework. Ok, Before I post a dumb solution can I just clarify that you need to just style the listview so that it only shows the contents of the listview item (i.e. just a button)?
SASS_Shooter 31-May-12 15:17pm    
Right now the ListView shows as a stark, white rectangle inside the very pretty floating control. I want the Listview to basically be 100% opaque (and my ListViewItems to also have an opaqueness to them) so that the control they are contained in appears to be holding the data instead of a control obviously sitting on top of it.
db7uk 31-May-12 15:30pm    
mmmmm ok... I think I understand. having a think.

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:

HTML
<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>


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.
 
Share this answer
 
v2
Comments
db7uk 1-Jun-12 11:38am    
Good job. Sorry for not thinking of a direct answer.
I think you need to create a transparent listviewItem like this:

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


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

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900