This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix : Binding Icon in ToolbarItem in TabbedPage doesn't refresh (#3761)
fixes #3756
- Loading branch information
1 parent
807aa56
commit 533d106
Showing
3 changed files
with
56 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Windows.Media; | ||
using Xamarin.Forms.Platform.WPF.Controls; | ||
using Xamarin.Forms.Platform.WPF.Enums; | ||
|
||
namespace Xamarin.Forms.Platform.WPF.Converters | ||
{ | ||
public class IconConveter : System.Windows.Data.IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is FileImageSource imageSource) | ||
{ | ||
if (Enum.TryParse(imageSource.File, true, out Symbol symbol)) | ||
return new FormsSymbolIcon() { Symbol = symbol }; | ||
else if (TryParseGeometry(imageSource.File, out Geometry geometry)) | ||
return new FormsPathIcon() { Data = geometry }; | ||
else if (Path.GetExtension(imageSource.File) != null) | ||
return new FormsBitmapIcon() { UriSource = new Uri(imageSource.File, UriKind.RelativeOrAbsolute) }; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
private bool TryParseGeometry(string value, out Geometry geometry) | ||
{ | ||
geometry = null; | ||
try | ||
{ | ||
geometry = Geometry.Parse(value); | ||
return true; | ||
} | ||
catch (Exception) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters