Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ImageSelector externally editable #836

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 10 additions & 15 deletions src/Shared/HandyControl_Shared/Controls/Input/ImageSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ private void SwitchImage(object sender, ExecutedRoutedEventArgs e)

if (dialog.ShowDialog() == true)
{
SetValue(UriPropertyKey, new Uri(dialog.FileName, UriKind.RelativeOrAbsolute));
SetValue(PreviewBrushPropertyKey, new ImageBrush(BitmapFrame.Create(Uri, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None))
SetValue(UriProperty, new Uri(dialog.FileName, UriKind.RelativeOrAbsolute));
SetValue(PreviewBrushProperty, new ImageBrush(BitmapFrame.Create(Uri, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None))
{
Stretch = Stretch
});
SetValue(HasValuePropertyKey, ValueBoxes.TrueBox);
SetValue(HasValueProperty, ValueBoxes.TrueBox);
SetCurrentValue(ToolTipProperty, dialog.FileName);
}
}
else
{
SetValue(UriPropertyKey, default(Uri));
SetValue(PreviewBrushPropertyKey, default(Brush));
SetValue(HasValuePropertyKey, ValueBoxes.FalseBox);
SetValue(UriProperty, default(Uri));
SetValue(PreviewBrushProperty, default(Brush));
SetValue(HasValueProperty, ValueBoxes.FalseBox);
SetCurrentValue(ToolTipProperty, default);
}
}
Expand All @@ -54,21 +54,18 @@ public Stretch Stretch
set => SetValue(StretchProperty, value);
}

public static readonly DependencyPropertyKey UriPropertyKey = DependencyProperty.RegisterReadOnly(
public static DependencyProperty UriProperty = DependencyProperty.Register(
"Uri", typeof(Uri), typeof(ImageSelector), new PropertyMetadata(default(Uri)));

public static readonly DependencyProperty UriProperty = UriPropertyKey.DependencyProperty;

public Uri Uri
{
get => (Uri) GetValue(UriProperty);
set => SetValue(UriProperty, value);
}

public static readonly DependencyPropertyKey PreviewBrushPropertyKey = DependencyProperty.RegisterReadOnly(
"PreviewBrush", typeof(Brush), typeof(ImageSelector), new PropertyMetadata(default(Brush)));

public static readonly DependencyProperty PreviewBrushProperty = PreviewBrushPropertyKey.DependencyProperty;
public static readonly DependencyProperty PreviewBrushProperty = DependencyProperty.Register(
"PreviewBrush", typeof(Brush), typeof(ImageSelector), new PropertyMetadata(default(Brush)));

public Brush PreviewBrush
{
Expand Down Expand Up @@ -112,11 +109,9 @@ public string Filter
set => SetValue(FilterProperty, value);
}

public static readonly DependencyPropertyKey HasValuePropertyKey = DependencyProperty.RegisterReadOnly(
public static readonly DependencyProperty HasValueProperty = DependencyProperty.Register(
"HasValue", typeof(bool), typeof(ImageSelector), new PropertyMetadata(ValueBoxes.FalseBox));

public static readonly DependencyProperty HasValueProperty = HasValuePropertyKey.DependencyProperty;

public bool HasValue
{
get => (bool) GetValue(HasValueProperty);
Expand Down