public void DeserializeXml(IResourceProvider theme, XmlReader xmlReader) { const string sVisualState = "VisualState"; Name = xmlReader.GetAttribute("Name"); string margin = xmlReader.GetAttribute("Margin"); Margin = String.IsNullOrEmpty(margin) ? Thickness.Empty : StyleHelper.DecodeThickness(margin); string textStyleClass = xmlReader.GetAttribute("TextStyle"); TextStyleClass = String.IsNullOrEmpty(textStyleClass) ? "Default" : textStyleClass; string width = xmlReader.GetAttribute("Width"); string height = xmlReader.GetAttribute("Height"); Width = String.IsNullOrEmpty(width) ? 0 : Single.Parse(width, CultureInfo.InvariantCulture); Height = String.IsNullOrEmpty(height) ? 0 : Single.Parse(height, CultureInfo.InvariantCulture); if (!xmlReader.ReadToDescendant(sVisualState)) { throw new InvalidOperationException(String.Format("{0}' element not found", sVisualState)); } visualStateDefinition = new VisualStateDefinition(); visualStateDefinition.DeserializeXml(theme, xmlReader); xmlReader.ReadEndElement(); }
internal static VisualState GenerateVisualStateForControl(VisualElement control, VisualStateDefinition visualStateDefinition) { var shapeList = new List <Shape>(); foreach (Shape shape in visualStateDefinition.Shapes) { var newShape = (Shape)shape.Copy(); newShape.ScaleX = shape.Width; newShape.ScaleY = shape.Height; newShape.Parent = control; newShape.DesignMode = true; newShape.IsInternal = true; newShape.HorizontalAlignment = control.HorizontalAlignment; newShape.VerticalAlignment = control.VerticalAlignment; newShape.PositionOffsets = control.PositionOffsets; shapeList.Add(newShape); } control.Animator.AddAnimations(visualStateDefinition.Animations); return(new VisualState(control, shapeList)); }