view raw
Kugelschreiber_Y Kugelschreiber_Y - 6 months ago 86
C# Question

ListView coloring of Rectangle in ViewBox WPF

I have a ListView which is binded to an ObservableCollection.

ItemsSource="{Binding CollectionOfObjects}"
SelectedItem="{Binding SelctedObj}" Margin="0,0,0,0"
ScrollViewer.VerticalScrollBarVisibility="Visible" BorderBrush="Orange" BorderThickness="1"
ScrollViewer.HorizontalScrollBarVisibility="Visible" FontSize="10"


<Style TargetType="ListViewItem">
<Setter Property="Height" Value="15"/>
<GridView >

<GridViewColumn DisplayMemberBinding="{Binding Name}" >
<GridViewColumnHeader Content="Name" Command="{Binding SortCommand}" CommandParameter="Name"/>

<GridViewColumn Header="Color">
<Viewbox Margin="0,0,0,0">
<Rectangle Fill="Red" Visibility="Visible"/>


For each object in my collection, it should display the name of it and simply a red rectangle on the right hand side.

I dont know why, but when I start the application it only appears the name without any coloured rectangle.
Above is a very simplyfied version of my code. All my bindings are working, also others I implemented in ViewBoxes.
Does anyone has an idea what the critical point is?


Give the rectangle a height and width.