You need to access the XAML resource where you saved the style. This is usually a way to save this in a separate resource file. Then you need to access the URI of this XAML file as a ResourceDictionary object. Here is an example when I use a converter to decide which style the item will receive.
namespace Shared.Converters { public class SaveStatusConverter : IValueConverter { public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) { bool? saveState = (bool?)value; Uri resourceLocater = new Uri("/Shared;component/Styles.xaml", System.UriKind.Relative); ResourceDictionary resourceDictionary = (ResourceDictionary)Application.LoadComponent(resourceLocater); if (saveState == true) return resourceDictionary["GreenDot"] as Style; if (saveState == false) return resourceDictionary["RedDot"] as Style; return resourceDictionary["GrayDot"] as Style; } public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new System.NotImplementedException(); } } }
source share