wpf - 超出网格的图像

标签 wpf

我不知道为什么图像越过网格右边框,如何修复?
代码看起来像这样:

    <Grid>
        <Grid Name="grid1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="260" />
                <ColumnDefinition Width="640" />
            </Grid.ColumnDefinitions>
            <Image Grid.Column="1" HorizontalAlignment="Stretch" Margin="0" Name="image1" Stretch="Fill" VerticalAlignment="Stretch" Source="path.png"/>
            <ListView Height="361" HorizontalAlignment="Left" Margin="10,10,0,0" Name="listView1" VerticalAlignment="Top" Width="240" ItemsSource="{Binding}" />
            <Button Content="Add New Gesture" Height="39" HorizontalAlignment="Left" Margin="10,387,0,0" Name="button1" VerticalAlignment="Top" Width="112" Click="button1_Click" />
            <Button Content="Delete" Height="39" HorizontalAlignment="Left" Margin="191,387,0,0" Name="button2" VerticalAlignment="Top" Width="59" />
            <Button Content="Modify" Height="39" HorizontalAlignment="Left" Margin="128,387,0,0" Name="button3" VerticalAlignment="Top" Width="57" />
        </Grid>
    </Grid>

最佳答案

这看起来像是您设置的固定宽度的效果(也许您的固定列宽之和大于固定窗口宽度?)这会导致网格单元格(和图像)从 View 中消失。

如果您希望图像填满窗口中剩余的整个空间,请更改您的第二个 ColumnDefinition宽度为 "*"而不是 640 :

<ColumnDefinition Width="*" />

关于wpf - 超出网格的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13425702/

相关文章:

c# - 如何在更新属性时调用代码隐藏中的方法?

c# - 将项目添加到未知类型的 ObservableCollection

wpf - 在样式触发器中为文本框设置焦点

sql-server - 我收到错误 “Incorrect syntax near the keyword ',其中“”

c# - WPF 文档查看器 : Navigate using internal link not accurate on first click

c# - 如何在 WPF 中获取以像素为单位的网格列宽?

c# - 将 Silverlight 移植到 WPF

c# - WPF绑定(bind)(使用触发器)不能从文本框工作到标签

c# - WPF 窗口最大化导致项目错位

c# - 如何在用户控件中以样式定义触发器