I have a grid with an overlaying separator which I am using as a cursor for the grid. I am programmatically moving the separator on the grid by setting the margin to a percentage of the grid ActualHeight. This works fine until the margin is set to more than (grid.ActualHeight / 2) at which point the separator is no longer visible.
I have tried setting the vertical alignment (which is defaulted to Top) to Bottom or Center and changing the location accordingly with similar results.
Is there some reason why the grid hides the separator? And how can I ensure the separator is visible?
Thanks,
Stuart
Edit:
Here is the XAML for the grid. Borders are added to the grid programmatically, which is why the grid contains the rows and columns.
<Grid Name="graph1" Grid.Row="1" Margin="2" MouseLeftButtonDown="MouseDown" Background="#00000000">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Separator Name="graph1Cursor" Grid.RowSpan="5" Grid.ColumnSpan="6" VerticalAlignment="Top"/>
</Grid>
And the code I am using for setting the margin:
graph1Cursor.Margin = new Thickness(0, y, 0, y);
where y is the height of the cursor location with respect to the ActualHeight of the grid.
I found a solution, although I’m not sure why the solution works over the original… Instead of putting the separator in the Grid directly, I nested it within a StackPanel. All the code other than that remained the same.
Here is the XAML for the Grid with nested StackPanel:
I will mark this as answered. If anyone has a better solution, I will remark it.