我正在開發一個應用程式,我面臨同樣的問題。由于某種原因,Path并沒有拉伸到程式視窗的整個區域(我以編程方式將應用程式視窗拉伸到兩個螢屏),但是 Path 似乎有自己的限制Width。這是路徑本身的標記
<Grid >
<InkCanvas Name="inkCanvas"
Cursor="Cross"
UseCustomCursor="True"
EditingMode="{Binding EditingMode}">
<InkCanvas.InputBindings>
<KeyBinding Command="{Binding CloseAppCommand}"
Key="Esc"/>
<KeyBinding Command="{Binding DrawModeCommand}"
Key="F1"/>
</InkCanvas.InputBindings>
<i:Interaction.Behaviors>
<if:MouseBehaviour MouseX="{Binding MouseX, Mode=OneWayToSource}"
MouseY="{Binding MouseY, Mode=OneWayToSource}" />
</i:Interaction.Behaviors>
<InkCanvas.Background>
<ImageBrush ImageSource="{Binding Screenshot.Source}"></ImageBrush>
</InkCanvas.Background>
<Path Stroke="Black" Fill="Green" Opacity=".3">
<Path.Data>
<CombinedGeometry GeometryCombineMode="Exclude">
<CombinedGeometry.Geometry1>
<RectangleGeometry Rect="{Binding BlackoutRect.Rect}" >
</RectangleGeometry>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<RectangleGeometry Rect="{Binding SelectionRect.Rect}" >
</RectangleGeometry>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Path.Data>
</Path>
</InkCanvas>
</Grid>
結果,我們看到下圖:
https://imgur.com/nqbqHFO
例如,如果我們為路徑指定Width="300px"
<Path Stroke="Black" Fill="Green" Opacity=".3" Width="300px"...
, 那么上面螢屏上的綠色區域的寬度實際上是300px,但是如果你指定例如300000px,圖片將和上面螢屏上的一樣。也就是說,我得出的結論是Path元素具有最大寬度(順便說一下,如果您指定MaxWitdh="30000px",那么無論如何都不會改變,它與上面的螢屏截圖中的相同)
因此,該執行緒的主要問題是:如何更改路徑元素的最大大小?
uj5u.com熱心網友回復:
InkCanvas 不會拉伸其子元素。
您可以添加一個執行所需布局的 Panel,并將其 Width 和 Height 系結到父 InkCanvas 的 ActualWidth 和 ActualHeight:
<InkCanvas ...>
...
<Grid Width="{Binding ActualWidth,
RelativeSource={RelativeSource AncestorType=InkCanvas}}"
Height="{Binding ActualHeight,
RelativeSource={RelativeSource AncestorType=InkCanvas}}">
<Path Stretch="Uniform" ...>
...
</Path>
</Grid>
</InkCanvas>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/431120.html
