HandyOrg / HandyOrg/HandyControl

ImageSelector控件在下一次打开时如何显示上一次选中的图片?

Open
#1,477 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

:factory: enhancement
Dominant language
C#
Stars
7.2k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

我使用的场景是为数据上传相应图片,最后复制到项目文件夹中并写入数据库。当我再编辑这条数据时给它换个图片,该控件就没有显示上一次我给它设置的。Uri属性因为只读,所以我照搬了控件切换图片方法的代码在编辑窗体加载后重设Uri内容,UI和后台代码:

<hc:ImageSelector Grid.Column="2"
                                  Grid.Row="2"
                                  Grid.RowSpan="3"
                                  x:Name="deviceImg"
                                  HorizontalAlignment="Left"
                                  Width="150"
                                  Margin="16 16 0 16"
                                  Filter="All Image Files|*.jpg;*.jpeg;*.png;*.gif;*.bmp"
                                  hc:BorderElement.CornerRadius="10"
                                  StrokeThickness="2"
                                  BorderThickness="2"
                                  Background="Transparent"
                                  BorderBrush="{DynamicResource PrimaryBrush}" />
this.deviceImg.Loaded += (sender, e) =>
{
       if (!string.IsNullOrWhiteSpace(model.imageSource))
       {
              deviceImg.SetValue(ImageSelector.UriPropertyKey, new Uri(model.imageSource));
              SetValue(ImageSelector.PreviewBrushPropertyKey, new ImageBrush(BitmapFrame.Create(deviceImg.Uri, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None))
              {
                   Stretch = deviceImg.Stretch
              });
              SetValue(ImageSelector.HasValuePropertyKey, true);
              SetCurrentValue(FrameworkElement.ToolTipProperty, "this is a picture");
      }
 };

无奈界面仍然没有显示,ToolTip倒是应用上了。在可视树中查看该控件属性,Uri确实已经有数据了。请教一下为什么不显示图片呢,是设计使然还是上述操作有问题,如何让其显示出来?谢谢

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the HandyControl ImageSelector implementation and its Uri, PreviewBrush, and HasValue properties, then compare their loading behavior with the Loaded handler shown in the issue. Reproduce reopening an existing record with an image path and verify that the control displays the previous image rather than only updating its Uri and tooltip.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.