Reputation: 632
I've made a program that draws shapes based on user input. I can currently only draw a circle. When I draw circles, its radius is based on the x
displacement and is not dependent on the y
. This means that I can make shapes that are bigger than the available window size. When I do this, it draws over the status bar like so:
Any idea how I could fix this? Here is the structure of the XAML
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="File">
<MenuItem Header="New"></MenuItem>
<MenuItem Header="Open"></MenuItem>
<MenuItem Header="Save"></MenuItem>
<Separator/>
<MenuItem Header="Exit" Click="MenuItem_Click"></MenuItem>
</MenuItem>
</Menu>
<StatusBar x:Name="status" DockPanel.Dock="Bottom" Height="22">
<TextBlock x:Name="statusText"></TextBlock>
</StatusBar>
<DockPanel>
<StackPanel DockPanel.Dock="Left">
<StackPanel.Background>
<SolidColorBrush Color="#EEE"></SolidColorBrush>
</StackPanel.Background>
<Button Padding="3,0" Margin="5" Click="CircleButton_Click">Circle</Button>
</StackPanel>
<Canvas Background="White" x:Name="canvas" MouseLeftButtonDown="CanvasDownHandler" MouseMove="CanvasMoveHandler" MouseLeftButtonUp="CanvasUpHandler">
</Canvas>
</DockPanel>
</DockPanel>
Upvotes: 0
Views: 405
Reputation: 265
You should set ClipToBounds=true for the canvas like this:
<Canvas Background="White" x:Name="canvas" MouseLeftButtonDown="CanvasDownHandler" MouseMove="CanvasMoveHandler" MouseLeftButtonUp="CanvasUpHandler" ClipToBounds=true>
this makes sure the elements inside the canvas don't draw outside the canvas itself
Upvotes: 1
Reputation: 365
If i understood correctly only change this line:
<StatusBar x:Name="status" DockPanel.Dock="Bottom" Height="22" Panel.ZIndex="100">
Panel.ZIndex="100" is property which tell the canvas order of painting.
Upvotes: 0