How to write the same thing, only in code?
xaml:
<ProgressBar Name="progbar" IsIndeterminate="False" Orientation="Horizontal" Height="30" Margin="46,392,10,10" Foreground="#FF1A94E8" /> <TextBlock Text="{Binding ElementName=progbar, Path=Value, StringFormat={}{0:0}%}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="376,359,418,57"/> I try so c #:
Duration duration = new Duration(TimeSpan.FromSeconds(10)); DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration); progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation); ProgressBar progbar1 = new ProgressBar(); progbar1.Name = "prr1"; progbar1.IsIndeterminate = false; progbar1.Orientation = Orientation.Horizontal; progbar1.Height = 30; progbar1.BeginAnimation(ProgressBar.ValueProperty, doubleanimation); progbar1.Margin = new Thickness(28, 10, 28, 392); progbar1.VerticalAlignment = VerticalAlignment.Top; grid.Children.Add(progbar1); TextBlock tb1 = new TextBlock(); Binding binding = new Binding(); binding.ElementName = "prr1"; binding.Path = new PropertyPath("Value"); binding.StringFormat = "{}{0:0}%}"; tb1.SetBinding(TextBlock.TextProperty, binding); tb1.Margin = new Thickness(0, 10, 0, 0); tb1.VerticalAlignment = VerticalAlignment.Top; tb1.HorizontalAlignment = HorizontalAlignment.Center; //tb1.Text = "asdasdasfasd"; grid.Children.Add(tb1); But something is not glued (presumably the band does not work), if you unwind the last but one line, the text appears.
binding.StringFormat = "{}{0:0}%}". Trybinding.StringFormat = "{0:0}%"- Andrew NOPSource, than to act throughElementName- Andrey NOPItemsControl(or his heirs) - Andrey NOP