void create() { Grid grid = new Grid(); grid.HorizontalAlignment = HorizontalAlignment.Center; grid.VerticalAlignment = VerticalAlignment.Center; grid.Background = null; Rating ratingControl = new Rating(); ratingControl.HorizontalAlignment = HorizontalAlignment.Left; ratingControl.VerticalAlignment = VerticalAlignment.Top; ratingControl.ItemCount = 5; ratingControl.Foreground = new SolidColorBrush(Colors.Red); ratingControl.Background = null; ratingControl.IsReadOnly = true; ratingControl.SelectionMode = RatingSelectionMode.Continuous; double scale = 0.6; ratingControl.LayoutTransform = new ScaleTransform(scale, scale); grid.Children.Add(ratingControl); int i = 0; double nrStars = 0; do { ratingControl.Value = nrStars; grid.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); grid.Arrange(new Rect(new Size(double.MaxValue, double.MaxValue))); Rect size = VisualTreeHelper.GetDescendantBounds(ratingControl); //grid.Arrange(new Rect(new Size(size.Width, size.Height))); RenderTargetBitmap bitmap = new RenderTargetBitmap((int)(size.Width * scale), (int)(size.Height * scale), 96, 96, PixelFormats.Default); Window dummy = new Window(); dummy.Content = grid; dummy.SizeToContent = SizeToContent.WidthAndHeight; dummy.Show(); bitmap.Render(ratingControl); RatingBitmap.Add(bitmap); nrStars += 1.0 / 5; BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmap, null, null, null)); FileStream outputFile = new FileStream("d:\\" + i + "stars.png", FileMode.Create); encoder.Save(outputFile); i++; } while (nrStars <= 1); }
/// <summary> /// Initializes a new instance of the <see cref="RatingAutomationPeer"/> class. /// </summary> /// <param name="owner">The Rating that is associated with this /// RatingAutomationPeer.</param> public RatingAutomationPeer(Rating owner) : base(owner) { }
public void resetRating() { eraseRating(); int indexCurrentRating = 1; //Reinitialise les notes var stackPanels = canvas.Children.OfType<StackPanel>().ToList(); foreach (var stackPanel in stackPanels) { Rating currentRate = new Rating { Maximum = 5, Minimum = 0, Tag = indexCurrentRating, Name = "rtFive" + indexCurrentRating.ToString() }; stackPanel.Children.Add(currentRate); indexCurrentRating++; } }
override protected void createHeader(Grid mainGrid, String fontFamily, int margin) { if (Vm.IsAddHeader == false) return; Grid headerGrid = new Grid(); headerGrid.Margin = new Thickness(margin, 0, 0, 0); ColumnDefinition labelColumn = new ColumnDefinition() { Width = GridLength.Auto }; ColumnDefinition valueColumn = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }; headerGrid.ColumnDefinitions.Add(labelColumn); headerGrid.ColumnDefinitions.Add(valueColumn); List<TextBlock> labels = new List<TextBlock>(); List<UIElement> values = new List<UIElement>(); labels.Add(new TextBlock(new Run("Filename: "))); TextBlock location = new TextBlock(new Run(Path.GetFileName(Video.Location))); location.TextWrapping = TextWrapping.Wrap; values.Add(location); labels.Add(new TextBlock(new Run("Container: "))); values.Add(new TextBlock(new Run(Video.VideoContainer))); if (Video.Software != null) { labels.Add(new TextBlock(new Run("Encoder: "))); values.Add(new TextBlock(new Run(Video.Software))); } labels.Add(new TextBlock(new Run("Video Codec: "))); String videoRate = Video.VideoBitRate.HasValue ? MiscUtils.formatSizeBytes(Video.VideoBitRate.Value / 8) + "/s" : ""; String videoCodecInfo = Video.VideoCodec + ", " + Video.Width + "x" + Video.Height + ", " + Video.FramesPerSecond.ToString("0.00") + "fps" + ", " + Video.PixelFormat + ", " + videoRate; values.Add(new TextBlock(new Run(videoCodecInfo))); if(Video.AudioCodec != null) { String audioRate = Video.AudioBitRate.HasValue ? MiscUtils.formatSizeBytes(Video.AudioBitRate.Value / 8) + "/s" : ""; labels.Add(new TextBlock(new Run("Audio Codec: "))); String audioCodecInfo = Video.AudioCodec + ", " + Video.NrChannels + "chan" + ", " + Video.SamplesPerSecond + "hz, " + Video.BitsPerSample + "bit" + ", " + audioRate; values.Add(new TextBlock(new Run(audioCodecInfo))); } labels.Add(new TextBlock(new Run("Duration: "))); values.Add(new TextBlock(new Run(MiscUtils.formatTimeSeconds(Video.DurationSeconds)))); labels.Add(new TextBlock(new Run("Size: "))); values.Add(new TextBlock(new Run(MiscUtils.formatSizeBytes(Video.SizeBytes)))); if (Video.Rating != null) { labels.Add(new TextBlock(new Run("Rating: "))); Rating ratingControl = new Rating(); ratingControl.HorizontalAlignment = HorizontalAlignment.Left; ratingControl.VerticalAlignment = VerticalAlignment.Top; ratingControl.ItemCount = 5; ratingControl.Foreground = new SolidColorBrush(Colors.Red); ratingControl.Background = null; ratingControl.IsReadOnly = true; ratingControl.SelectionMode = RatingSelectionMode.Continuous; ratingControl.Value = Video.Rating * (1.0 / 5); values.Add(ratingControl); } if (Video.Tags.Count > 0 && Vm.IsAddTags) { labels.Add(new TextBlock(new Run("Tags: "))); String tags = Video.Tags.ElementAt(0).Name; for (int i = 1; i < Video.Tags.Count(); i++) { tags += ", " + Video.Tags.ElementAt(i).Name; } TextBlock tagsTextBlock = new TextBlock(new Run(tags)); tagsTextBlock.TextWrapping = TextWrapping.Wrap; values.Add(tagsTextBlock); } if (!String.IsNullOrEmpty(Vm.Comment) && Vm.IsCommentEnabled) { labels.Add(new TextBlock(new Run("Comment: "))); values.Add(new TextBlock(new Run(Vm.Comment))); } for (int i = 0; i < labels.Count; i++) { RowDefinition row = new RowDefinition() { Height = GridLength.Auto }; headerGrid.RowDefinitions.Add(row); Grid.SetRow(labels[i],i); Grid.SetColumn(labels[i],0); Grid.SetRow(values[i],i); Grid.SetColumn(values[i],1); headerGrid.Children.Add(labels[i]); headerGrid.Children.Add(values[i]); labels[i].TextAlignment = TextAlignment.Right; Run labelRun = ((Run)labels[i].Inlines.First()); labelRun.FontFamily = new FontFamily(fontFamily); labelRun.FontSize = Vm.FontSize; labelRun.Foreground = new SolidColorBrush(FontColor); if (values[i] is TextBlock) { TextBlock value = values[i] as TextBlock; Run valueRun = (Run)value.Inlines.First(); valueRun.FontFamily = new FontFamily(fontFamily); valueRun.FontSize = Vm.FontSize; valueRun.Foreground = new SolidColorBrush(FontColor); } } Grid.SetRow(headerGrid, 0); mainGrid.Children.Add(headerGrid); }
/// <summary> /// DisplayValueProperty property changed handler. /// </summary> /// <param name="dependencyObject">Rating that changed its DisplayValue.</param> /// <param name="eventArgs">Event arguments.</param> private static void OnDisplayValueChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs) { Rating source = (Rating)dependencyObject; source.OnDisplayValueChanged(); }
/// <summary> /// Create an object on a Wrap/Stack-panel /// </summary> /// <param name="eValue">Value</param> /// <param name="pnlInner"></param> /// <param name="objType"></param> private void CreateElement(XElement eValue, object pnlInner) { string[] KeyValuePairArray; string[] KeyValuePair; string[] seperatorKeyValue = new string[] { "=" }; // object specific setup object obj = null; if (eValue.Attribute("id").Value.ToString().Contains("_nmlbl")) { obj = new Label(); (obj as Label).Content = eValue.Value; KeyValuePairArray = GetLayoutAttributes(eValue, (int)CreateItemEnum.enLabelTitle); } else if (eValue.Attribute("id").Value.ToString().Contains("_lbl")) { obj = new Label(); if (eValue.Element("start") != null) (obj as Label).Content = eValue.Element("start").Value; KeyValuePairArray = GetLayoutAttributes(eValue, (int)CreateItemEnum.enLabel); } else if (eValue.Attribute("id").Value.ToString().Contains("_cmbbx")) { obj = new ComboBox(); string start = ""; List<string> lItem = new List<string>((from item in eValue.Elements("item") select item.Value).ToList()); if (eValue.Element("start") != null) { if (lItem.IndexOf(eValue.Element("start").Value) == -1) lItem.Add(eValue.Element("start").Value); start = eValue.Element("start").Value; } lItem.Sort(); lItem.ForEach(delegate(string itm) { (obj as ComboBox).Items.Add(itm); }); (obj as ComboBox).SelectedItem = eValue.Element("start").Value; KeyValuePairArray = GetLayoutAttributes(eValue, (int)CreateItemEnum.enComboBox); } else if (eValue.Attribute("id").Value.ToString().Contains("_txtbx")) { obj = new TextBox(); if (eValue.Element("start") != null) (obj as TextBox).Text = eValue.Element("start").Value; (obj as TextBox).TextWrapping = TextWrapping.Wrap; if (eValue.Attribute("id").Value.ToString().Contains("_txtbxrdo")) (obj as TextBox).IsReadOnly = true; KeyValuePairArray = GetLayoutAttributes(eValue, (int)CreateItemEnum.enTextBox); } else if (eValue.Attribute("id").Value.ToString().Contains("_dt")) { obj = new Rating(); (obj as Rating).ItemCount = int.Parse(eValue.Element("maxshow").Value); if (eValue.Element("start") != null) (obj as Rating).Value = float.Parse(eValue.Element("start").Value) / (obj as Rating).ItemCount; switch (eValue.Element("look").Value) { case "dot": (obj as Rating).ItemContainerStyle = (Application.Current.Resources["RatingItemStyleDot"] as Style); break; case "square": (obj as Rating).ItemContainerStyle = (Application.Current.Resources["RatingItemStyleSquare"] as Style); break; default: break; } KeyValuePairArray = GetLayoutAttributes(eValue, (int)CreateItemEnum.enDot); } else if (eValue.Attribute("id").Value.ToString().Contains("_nmud")) { obj = new NumericUpDown(); if (eValue.Element("start") != null) (obj as NumericUpDown).Value = double.Parse(eValue.Element("start").Value); KeyValuePairArray = GetLayoutAttributes(eValue, (int)CreateItemEnum.enNumericUpDown); } else throw new UnknownObjectException(eValue.Attribute("id").Value.ToString()); // set object name (obj as Control).Name = eValue.Attribute("id").Value.ToString(); // set layout of object foreach (string str in KeyValuePairArray) { KeyValuePair = str.Split(seperatorKeyValue, StringSplitOptions.RemoveEmptyEntries); SetObjectAttribute(obj, KeyValuePair); } (pnlInner as Panel).Children.Add((obj as Control)); }