Wpf 使用窗口调整对象大小
环顾四周,找到一种方法来调整窗口大小绑定的大小,而无需明确告诉我的对象获取窗口大小。
这是代码:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<WindowsFormsHost Background="{x:Null}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Name="windowsFormsHost1" VerticalAlignment="Top" Margin="-1,0,0,0">
<wf:Panel x:Name="pnlLivePreview" />
</WindowsFormsHost>
</Grid>
随后的示例显示 此处
编辑:问题:为什么面板不随窗口调整大小?
Looked around to find a way to resize bind with the windows resize without explicitly telling my object to grab the windows size.
Here is the code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<WindowsFormsHost Background="{x:Null}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Name="windowsFormsHost1" VerticalAlignment="Top" Margin="-1,0,0,0">
<wf:Panel x:Name="pnlLivePreview" />
</WindowsFormsHost>
</Grid>
This was followed by the example showed here
Edit: Question: Why doesn't panel resize with the window ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
显式的
Width
和Height
设置,以及HorizontalAlignment
和VerticalAlignment
设置,因此:只需删除 在这里进行大胆的猜测,但由于这是一个
WinForms
面板,请尝试将其Dock
属性设置为Fill
因此:真的不确定它会工作,如果它在标记中不起作用,请尝试在代码中执行。
Simply remove the explicit
Width
andHeight
settings, and theHorizontalAlignment
andVerticalAlignment
settings, thus:I'm going to throw a wild guess here, but since this is a
WinForms
panel, try setting it'sDock
property toFill
thus:Really not sure it would work, if it doesn't work in markup, try doing it in code.
将您的高度/宽度绑定到窗口的高度/宽度
Bind your Height/Width to your window's height/width
答案:问题不在于面板,而在于用于创建面板内容的 api。
The answer: Problem is not the panel but the api used to create the content of it.