private static DataTemplate TryFindDataTemplate(FrameworkElement element, object dataTemplateKey)
 {
     object dataTemplate = element.TryFindResource(dataTemplateKey);
     if (dataTemplate == null)
     {
         dataTemplateKey = new ComponentResourceKey(typeof(PropertyGrid), dataTemplateKey);
         dataTemplate = element.TryFindResource(dataTemplateKey);
     }
     return dataTemplate as DataTemplate;
 }
 private static DataTemplate TryFindDataTemplate(FrameworkElement element, object dataTemplateKey)
 {
     if (dataTemplateKey.ToString().Contains("Task"))
     {
         // Todo: remove me after testing.
     }
     object dataTemplate = element.TryFindResource(dataTemplateKey);
     if (dataTemplate == null)
     {
         dataTemplateKey = new ComponentResourceKey(typeof(PropertyGrid), dataTemplateKey);
         dataTemplate = element.TryFindResource(dataTemplateKey);
     }
     return dataTemplate as DataTemplate;
 }
        public ClientInformation()
        {
            InitializeComponent();

            try
            {
                frameworkElement = new FrameworkElement();
                textBoxNormalStyle = (Style)frameworkElement.TryFindResource("textBoxNormalStyle");
                textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxErrorStyle");
            }
            catch (Exception ex)
            {
                Helper.LogException(ex);
            }
        }
        /// <summary>
        /// Find a DataTemplate for the specified type in the visual-tree.
        /// </summary>
        public static DataTemplate FindDataTemplate(Type type, FrameworkElement element)
        {
            var dataTemplate = element.TryFindResource(new DataTemplateKey(type)) as DataTemplate;
            if (dataTemplate != null)
            {
                return dataTemplate;
            }

            if (type.BaseType != null && type.BaseType != typeof(object))
            {
                dataTemplate = FindDataTemplate(type.BaseType, element);
                if (dataTemplate != null)
                {
                    return dataTemplate;
                }
            }

            foreach (var interfaceType in type.GetInterfaces())
            {
                dataTemplate = FindDataTemplate(interfaceType, element);
                if (dataTemplate != null)
                {
                    return dataTemplate;
                }
            }

            return null;
        }
Example #5
0
        internal static bool IsNumberOnly(TextBox input)
        {
            bool result = false;
            try
            {
                if (Regex.IsMatch(input.Text, @"^\d+$"))
                {
                    SetToDefaultStyle(input);
                    result = true;
                }
                else
                {
                    Style textBoxErrorStyle;
                    FrameworkElement frameworkElement;
                    frameworkElement = new FrameworkElement();
                    //textBoxNormalStyle = (Style)frameworkElement.TryFindResource("textBoxNormalStyle");
                    textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxNumericErrorStyle");
                    input.Style = textBoxErrorStyle;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return result;
        }
Example #6
0
        internal static bool IsNonEmpty(TextBox input)
        {
            bool result = false;
            try
            {
                if (false == string.IsNullOrEmpty(input.Text))
                {
                    SetToDefaultStyle(input);

                    result = true;
                }
                else
                {
                    Style textBoxErrorStyle;
                    FrameworkElement frameworkElement;
                    frameworkElement = new FrameworkElement();
                    textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxEmptyErrorStyle");
                    input.Style = textBoxErrorStyle;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return result;
        }
Example #7
0
 public ResourceItem(object resourceKey, ResourceDictionary dictionary, FrameworkElement source, ResourceScope resourceScope)
 {
     _resourceKey = resourceKey;
     _resourceScope = resourceScope;
     _dictionary = dictionary;
     _value = dictionary[resourceKey];
     if( _value == null)
     {
         _value = source.TryFindResource(resourceKey);
     }
 }
        /// <summary>
        /// Creates a best matching resource item for the provided resource
        /// </summary>
        public static ResourceItem CreateResourceItem(object resourceKey, ResourceDictionary dictionary, FrameworkElement source, ResourceScope scope)
        {
            var resource = dictionary[resourceKey] ?? source.TryFindResource(resourceKey);

            if (resource is Style) return new StyleResourceItem(resourceKey, dictionary, source, scope);
            if (resource is Brush) return new BrushResourceItem(resourceKey, dictionary, source, scope);
            if (resource is Drawing) return new DrawingResourceItem(resourceKey, dictionary, source, scope);
            if (resource is Color) return new ColorResourceItem(resourceKey, dictionary, source, scope);
            if (resource is Geometry) return new GeometryResourceItem(resourceKey, dictionary, source, scope);

            return new ResourceItem(resourceKey, dictionary, source, scope);
        }
 protected virtual DataTemplate FindResource(FrameworkElement container, string key)
 {
     return container.TryFindResource(key) as DataTemplate;
 }
Example #10
0
 private static void SetToDefaultStyle(TextBox input)
 {
     try
     {
         Style txtNormalStyle;
         FrameworkElement frameworkElement;
         frameworkElement = new FrameworkElement();
         txtNormalStyle = (Style)frameworkElement.TryFindResource("DefaultTextBox");
         input.Style = txtNormalStyle;
     }
     catch (Exception ex)
     {
         Logger.LogException(ex);
     }
 }
Example #11
0
        internal static bool IsValidPhone(TextBox input)
        {
            bool result = false;
            try
            {
                if (input.Text == string.Empty)
                {
                    SetToDefaultStyle(input);
                    return true;
                }
                if (Regex.IsMatch(input.Text, @"^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$"))
                //if (Regex.IsMatch(input.Text, @"/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/"))
                {
                    SetToDefaultStyle(input);
                    result = true;
                }
                else
                {
                    Style textBoxErrorStyle;
                    FrameworkElement frameworkElement;
                    frameworkElement = new FrameworkElement();
                    textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxPhoneErrorStyle");
                    input.Style = textBoxErrorStyle;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return result;
        }
Example #12
0
        internal static bool IsValidEmail(TextBox input)
        {
            bool result = false;
            try
            {
                if (input.Text == string.Empty)
                {
                    SetToDefaultStyle(input);
                    return true;
                }

                if (Regex.IsMatch(input.Text, @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"))
                {
                    SetToDefaultStyle(input);
                    result = true;
                }
                else
                {
                    Style textBoxErrorStyle;
                    FrameworkElement frameworkElement;
                    frameworkElement = new FrameworkElement();
                    textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxEmailErrorStyle");
                    input.Style = textBoxErrorStyle;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return result;
        }
Example #13
0
 private static Binding TryCreateBinding(FrameworkElement e, string resourceName)
 {
     var resource = e.TryFindResource(resourceName);
     if (resource != null)
         return new Binding { Source = resource, IsAsync = true };
     return null;
 }
Example #14
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (!(value is BaloonMode)) return null;
     var mode = (BaloonMode)value;
     var fe = new FrameworkElement();
     switch (mode)
     {
         case BaloonMode.FirstRun:
             return fe.TryFindResource("thumbs_up") as BitmapImage;
         //return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "thumbs_up.png"));
         case BaloonMode.NewVersion:
         case BaloonMode.CriticalUpdates:
             return fe.TryFindResource("package_new") as BitmapImage;
         //return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "package_new.png"));
         case BaloonMode.NoteSent:
             return fe.TryFindResource("outbox_out") as BitmapImage;
         //return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "outbox_out.png"));
         case BaloonMode.NoteReceived:
             return fe.TryFindResource("inbox_into") as BitmapImage;
         //return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "inbox_into.png"));
         case BaloonMode.Error:
             return fe.TryFindResource("error") as BitmapImage;
         //return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "error.png"));
         case BaloonMode.Information:
             return fe.TryFindResource("information") as BitmapImage;
         //return new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "information.png"));
         default:
             return null;
     }
 }
Example #15
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     var fe = new FrameworkElement();
     if (!(value is ContactConnection))
         return fe.TryFindResource("ContDisconnected");
     switch ((ContactConnection)value)
     {
         case ContactConnection.Connected:
             return fe.TryFindResource("ContConnected");
         default:
             return fe.TryFindResource("ContDisconnected");
     }
 }
Example #16
0
        internal static bool IsValidCurrency(TextBox input)
        {
            bool result = false;
            try
            {
                if (input.Text == "0.00")
                {
                    SetToDefaultStyle(input);
                    return true;
                }

                if (false == string.IsNullOrEmpty(input.Text) && Regex.IsMatch(input.Text, @"^[0-9]*(?:\.[0-9]*)?$"))
                {
                    SetToDefaultStyle(input);

                    result = true;
                }
                else
                {
                    Style textBoxErrorStyle;
                    FrameworkElement frameworkElement;
                    frameworkElement = new FrameworkElement();
                    textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxCurrencyErrorStyle");
                    input.Style = textBoxErrorStyle;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return result;
        }
        private Style GetBasedOnStyle(FrameworkElement frameworkElement)
        {
            if (frameworkElement == null)
                return null;

            return frameworkElement.TryFindResource(BasedOn) as Style;
        }
Example #18
0
        private static Ruban GenRuban(string str, FrameworkElement uc, Base.LibGroup tuple, bool gray)
        {
            Ruban rb = null;
            if (str == "C0")
                rb = new Ruban(uc.TryFindResource("tuxCard000") as Image, 0);
            else if (str.StartsWith("C"))
            {
                ushort ut = ushort.Parse(str.Substring(1));
                Tux tux = tuple.TL.DecodeTux(ut);
                if (tux != null)
                {
                    Image image = uc.TryFindResource("tuxCard" + tux.Code) as Image;
                    if (image != null)
                        rb = new Ruban(image, ut);
                    else
                        rb = new Ruban(uc.TryFindResource("tuxCard000") as Image, ut);
                }
                else
                    rb = new Ruban(uc.TryFindResource("tuxCard000") as Image, ut);
                rb.ToolTip = Tips.IchiDisplay.GetTuxTip(tuple, ut);
            }
            else if (str.StartsWith("M"))
            {
                ushort ut = ushort.Parse(str.Substring(1));
                NMB nmb = NMBLib.Decode(ut, tuple.ML, tuple.NL);
                if (nmb != null)
                {
                    Image image = uc.TryFindResource("monCard" + nmb.Code) as Image;
                    Image2Gray(ref image, gray);
                    if (image != null)
                        rb = new Ruban(image, ut);
                    else
                        rb = new Ruban(uc.TryFindResource("monCard000") as Image, ut);
                    if (nmb.IsMonster())
                        rb.ToolTip = Tips.IchiDisplay.GetMonTip(tuple, NMBLib.OriginalMonster(ut));
                    else if (nmb.IsNPC())
                        rb.ToolTip = Tips.IchiDisplay.GetNPCTip(tuple, NMBLib.OriginalNPC(ut));
                }
                else
                    rb = new Ruban(uc.TryFindResource("monCard000") as Image, ut);
            }
            else if (str.StartsWith("H0"))
                rb = new Ruban(uc.TryFindResource("hroCard000") as Image, 0);
            else if (str.StartsWith("H"))
            {
                ushort ut = ushort.Parse(str.Substring("H".Length));
                Hero hro = tuple.HL.InstanceHero(ut);
                if (hro != null)
                {
                    Image image = uc.TryFindResource("hroCard" + hro.Ofcode) as Image;
                    Image2Gray(ref image, gray);
                    if (image != null)
                        rb = new Ruban(image, ut);
                    else
                        rb = new Ruban(uc.TryFindResource("hroCard000") as Image, ut);
                }
                else rb = new Ruban(uc.TryFindResource("hroCard000") as Image, ut);
                rb.ToolTip = Tips.IchiDisplay.GetHeroTip(tuple, ut);
            }
            else if (str.StartsWith("D"))
            {
                ushort ut = ushort.Parse(str.Substring("D".Length));
                Image image = uc.TryFindResource("diceImg" + ut) as Image;
                if (image != null)
                    rb = new Ruban(image, ut);
                else
                    rb = new Ruban(uc.TryFindResource("diceImg000") as Image, ut);
                rb.ToolTip = null;
            }
            else if (str.StartsWith("G"))
            {
                ushort dbSerial = ushort.Parse(str.Substring("G".Length));
                Tux tux = tuple.TL.EncodeTuxDbSerial(dbSerial);
                if (tux != null)
                {
                    Image image = uc.TryFindResource("tuxCard" + tux.Code) as Image;
                    Image2Gray(ref image, gray);
                    if (image != null)
                        rb = new Ruban(image, dbSerial);
                    else
                        rb = new Ruban(uc.TryFindResource("tuxCard000") as Image, dbSerial);
                    rb.ToolTip = Tips.IchiDisplay.GetTuxDbSerialTip(tuple, dbSerial);
                }
                else
                    rb = new Ruban(uc.TryFindResource("tuxCard000") as Image, dbSerial);
            }
            else if (str.StartsWith("I"))
            {
                ushort ut = ushort.Parse(str.Substring("I".Length));
                Image image = uc.TryFindResource("exspCard" + ut) as Image;
                if (image != null)
                    rb = new Ruban(image, ut);
                else
                    rb = new Ruban(uc.TryFindResource("diceImg000") as Image, ut);
                rb.ToolTip = Tips.IchiDisplay.GetExspTip(tuple, "I" + ut);
            }
            else if (str.StartsWith("E0"))
            {
                Image image = uc.TryFindResource("eveCard000") as Image;
                image.RenderTransform = new RotateTransform(90);
                rb = new Ruban(image, 0);
            }
            else if (str.StartsWith("E"))
            {
                ushort ut = ushort.Parse(str.Substring("E".Length));
                Evenement eve = tuple.EL.DecodeEvenement(ut);
                Image image = uc.TryFindResource("eveCard" + eve.Code) as Image
                    ?? uc.TryFindResource("eveCard000") as Image;

                FormatConvertedBitmap bp = new FormatConvertedBitmap();
                bp.BeginInit();
                bp.Source = image.Source as BitmapSource;
                bp.EndInit();

                TransformedBitmap tb = new TransformedBitmap();
                tb.BeginInit();
                tb.Source = bp;
                tb.Transform = new RotateTransform(90);
                tb.EndInit();

                image = new Image() { Source = tb };
                Image2Gray(ref image, gray);
                rb = new Ruban(image, ut);
                rb.ToolTip = Tips.IchiDisplay.GetEveTip(tuple, ut);
            }
            else if (str.StartsWith("R"))
            {
                ushort ut = ushort.Parse(str.Substring("R".Length));
                Image image = uc.TryFindResource("runeCard" + ut) as Image;
                if (image != null)
                    rb = new Ruban(image, ut);
                else
                    rb = new Ruban(uc.TryFindResource("runeCard000") as Image, ut);
                rb.ToolTip = Tips.IchiDisplay.GetRuneTip(tuple, ut);
            }
            else if (str.StartsWith("V"))
            {
                ushort ut = ushort.Parse(str.Substring("V".Length));
                Image image = uc.TryFindResource("fiveImg" + ut) as Image;
                if (image != null)
                    rb = new Ruban(image, ut);
                else
                    rb = new Ruban(uc.TryFindResource("diceImg000") as Image, ut);
                rb.ToolTip = Tips.IchiDisplay.GetFiveTip(tuple, ut);
            }
            return rb;
        }
        /// <summary>
        /// The try to find data template.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="type">
        /// The type.
        /// </param>
        /// <returns>
        /// </returns>
        private static DataTemplate TryToFindDataTemplate(FrameworkElement element, Type type)
        {
            var key = new ComponentResourceKey(typeof(PropertyEditor), type);

            // todo: this command throws an exception
            return element.TryFindResource(key) as DataTemplate;
        }
 /// <summary>
 /// The try to find data template.
 /// </summary>
 /// <param name="element">
 /// The element.
 /// </param>
 /// <param name="key">
 /// The key.
 /// </param>
 /// <returns>
 /// </returns>
 private static DataTemplate TryToFindDataTemplate(FrameworkElement element, string key)
 {
     var resource = element.TryFindResource(key);
     return resource as DataTemplate;
 }
Example #21
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (!(value is bool)) return null;
     var fe = new FrameworkElement();
     return (bool)value ? fe.TryFindResource("SmallButtonBrush") : fe.TryFindResource("DisabledTextBrush");
 }
Example #22
0
		IEnumerable<string> GetDataTemplateStrings(FrameworkElement fwElem) {
			var obj = Page.GetStringsObject();
			if (obj == null)
				return Array.Empty<string>();

			var uiElem = obj as UIElement;
			if (uiElem != null)
				return GetStrings(uiElem);

			var key = new DataTemplateKey(obj as Type ?? obj.GetType());
			var dt = fwElem.TryFindResource(key) as DataTemplate;
			if (dt == null)
				return Array.Empty<string>();

			return GetStrings(dt.LoadContent());
		}