我重寫邊境控制,在我重寫的OnRender我做的:爲什麼我的座標(1,1)從(0,1)開始?
protected override void OnRender(System.Windows.Media.DrawingContext dc)
{
this.SnapsToDevicePixels = true;
this.VisualEdgeMode = EdgeMode.Aliased;
var myPen = new Pen(new SolidColorBrush(Colors.LightGray), 1);
dc.DrawLine(myPen, new Point(1, 1), new Point(1, RenderSize.Height - 1));
return;
這給了我這樣的結果:
問:
是否有人能告訴我爲什麼我的代碼畫一條從(0,1)開始的行,而假設從(1,1)開始,就像寫在代碼中一樣?
我的DPI都是96,96
對於裁判,這是我的XAML:
<Window xmlns:MyControls="clr-namespace:MyControls;assembly=MyControls" x:Class="TestControls.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<MyControls:Border3D BorderThickness="3" BorderBrush="Aqua">
<Rectangle Width="74" Height="3" HorizontalAlignment="Left">
<Rectangle.Fill>
<SolidColorBrush Color="#40FF0000">
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
</MyControls:Border3D>
<Rectangle Grid.Row="1" Grid.Column="0" Width="80" Grid.ColumnSpan="2" HorizontalAlignment="Left">
<Rectangle.Fill>
<SolidColorBrush Color="LightGray"></SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Window>
,這種行爲是否仍然發生? – Kcvin
看來,我猜你沒有計算邊界線..所以當你試圖畫(1,1)你在screeen上看到(0,1)..試試這個:new Point(1+ border。 TopLine.Height,1 + border.LeftWall.width)注意:給定的代碼是PSEUDO,因此可能在.NET中找不到方法/字段爲相同的名稱 – sihirbazzz
謝謝。克萊門斯似乎對我的答案有確切的答案,並且我會說一些很好的額外解釋:-)! –