Kugelschreiber_Y Kugelschreiber_Y - 1 year ago 185
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?

Answer Source

Give the rectangle a height and width.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download