0

This is a link for a question asked before, which concerns a TreeView:

WPF TreeView: How to style selected items with rounded corners like in Explorer

And this is another link for another question asked too, which concerns a ListView:

WPF ListView: How to style selected items with rounded corners like in Explorer

My question is : How to migrate this Solution on a UniformGrid ? Because I want to have the same effect as shown in the 2 examples, on my UniformGrid Cells.

here is an example of my source code:

<Grid VerticalAlignment="Center" HorizontalAlignment="Center" >
    <ItemsControl ItemsSource="{Binding ChildrenList}"  BorderThickness="0"  
        HorizontalContentAlignment="Center" VerticalContentAlignment="Center" >
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Columns="{Binding NumberOfColumns}" HorizontalAlignment=
                    "Center" Background="Transparent" Margin="4,4,4,4" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</Grid>
Community
  • 1
  • 1
NTinkicht
  • 972
  • 2
  • 12
  • 34
  • 1
    Hey buddy, there are no selected items in a `UniformGrid`. Please add more to your question to explain exactly what you want this time. – Sheridan Oct 08 '13 at 14:46
  • Ok @Sheridan, I'll explain more. – NTinkicht Oct 08 '13 at 14:49
  • Sorry my friend, but that still doesn't really explain what you want... do you want the `Style` for the `UniformGrid` or for the items inside it? If you want it for the items inside, you could have a problem as there is no such control as a `UniformGridItem` - instead, you can put any `UIElement` in there. The `Style` would then very much have to depend on the type of objects that will go into the grid. – Sheridan Oct 08 '13 at 15:07
  • Yes It concerns the Items inside the UniformGrid... I think I'll remove it and change it with a composition of ListView (Vertical List, which contains Horizontal Lists) – NTinkicht Oct 08 '13 at 15:16

1 Answers1

1

You're half-way there already :)

You need to use a ListBox instead of an ItemsControl (because ItemsControl doesn't handle selection and has no such thing as a "selected item").

Then you use the same ItemsPanel as in your example, and the same ItemContainerStyle as in the ListView post you linked to (note: just make sure you rename stuff from "ItemsControl"/"ListView" and "ListViewItem" to "ListBox" and "ListBoxItem"):

<ListBox ItemsSource="{Binding ChildrenList}" >
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="{Binding NumberOfColumns}" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>

    <!-- NOTE: "ListBox" and "ListBoxItem": -->
    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            ...
        </Style>
    </ListBox.ItemContainerStyle>

</ListBox>
Sphinxxx
  • 12,484
  • 4
  • 54
  • 84