Wpf 使用窗口调整对象大小

发布于 2024-10-25 20:11:37 字数 771 浏览 2 评论 0原文

环顾四周,找到一种方法来调整窗口大小绑定的大小,而无需明确告诉我的对象获取窗口大小。

这是代码:

    <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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

木森分化 2024-11-01 20:11:37

显式的 WidthHeight 设置,以及 Horizo​​ntalAlignmentVerticalAlignment 设置,因此:

<WindowsFormsHost Background="{x:Null}" 
                  Name="windowsFormsHost1" 
                  Margin="-1,0,0,0">
    <wf:Panel x:Name="pnlLivePreview" />
</WindowsFormsHost>

只需删除 在这里进行大胆的猜测,但由于这是一个 WinForms 面板,请尝试将其 Dock 属性设置为 Fill 因此:

    <wf:Panel x:Name="pnlLivePreview" Dock="Fill" />

真的不确定它会工作,如果它在标记中不起作用,请尝试在代码中执行。

Simply remove the explicit Width and Height settings, and the HorizontalAlignment and VerticalAlignment settings, thus:

<WindowsFormsHost Background="{x:Null}" 
                  Name="windowsFormsHost1" 
                  Margin="-1,0,0,0">
    <wf:Panel x:Name="pnlLivePreview" />
</WindowsFormsHost>

I'm going to throw a wild guess here, but since this is a WinForms panel, try setting it's Dock property to Fill thus:

    <wf:Panel x:Name="pnlLivePreview" Dock="Fill" />

Really not sure it would work, if it doesn't work in markup, try doing it in code.

℉絮湮 2024-11-01 20:11:37

将您的高度/宽度绑定到窗口的高度/宽度

<Window x:Name="Root_Window">
  <Grid Height="{Binding ElementName=RootWindow, Path=ActualHeight}"
        Width="{Binding ElementName=RootWindow, Path=ActualWidth}">
      <!-- Content Here -->
  </Grid>
</Window>

Bind your Height/Width to your window's height/width

<Window x:Name="Root_Window">
  <Grid Height="{Binding ElementName=RootWindow, Path=ActualHeight}"
        Width="{Binding ElementName=RootWindow, Path=ActualWidth}">
      <!-- Content Here -->
  </Grid>
</Window>
止于盛夏 2024-11-01 20:11:37

答案:问题不在于面板,而在于用于创建面板内容的 api。

The answer: Problem is not the panel but the api used to create the content of it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文