我在 wpf 工作。我有一个 userControl,其中有一个 Image 控件。
我通过 image.source 向这个 userControl 添加了一个 BitmapImage。
然后将此 userControl 添加到画布中,附加到此画布的任何控件都附加了装饰器,以便可以拖动四个角中的每一个来调整 userControl 的大小。
我的问题是,位图没有使用 userControl 调整大小。
当 userControl 调整大小时,是否有一种简单的方法可以使位图重绘?
这是用户控件的 XAML:
<UserControl x:Name="cusImageControl" x:Class="StoryboardTool.CustomImage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" BorderThickness="0" MouseDown="cusImageControl_MouseDown">
    <Image x:Name="image"  >
        <Image.ContextMenu>
            <ContextMenu>
                <MenuItem x:Name="ContextMenuBringForward" Header="BringForward" Click="ContextMenuBringForward_Click"/>
                <MenuItem x:Name="ContextMenuSendBackward" Header="SendBackward" Click="ContextMenuSendBackward_Click"/>
            </ContextMenu>
        </Image.ContextMenu>
    </Image>
</UserControl>
public void chooseImage()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "Choose Image to Add";
            if (ofd.ShowDialog() == true)
            {
                BitmapImage bImage = new BitmapImage();
                bImage.BeginInit();
                bImage.UriSource = new Uri(ofd.FileName);
                bImage.EndInit();
                image.Width = bImage.Width;
                image.Height = bImage.Height;
                image.Source = bImage;
                //image.Stretch = Stretch.Fill;
            }
        }