Guest User

Untitled

a guest
Dec 18th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. XAML
  2. <Window x:Class="ControlTest.MainWindow"
  3.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5.         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6.         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  7.         xmlns:local="clr-namespace:ControlTest"
  8.         mc:Ignorable="d"
  9.         Title="MainWindow" Height="450" Width="800">
  10.     <StackPanel Width="100" x:Name="spMain">
  11.         <Button />
  12.         <Button />
  13.         <Button />
  14.         <Label Content="Yo." />
  15.         <Button />
  16.         <Button />
  17.         <Button />
  18.     </StackPanel>
  19. </Window>
  20.  
  21. Code
  22. using System;
  23. using System.Windows;
  24. using System.Windows.Controls;
  25.  
  26. namespace ControlTest
  27. {
  28.     public partial class MainWindow : Window
  29.     {
  30.         public MainWindow()
  31.         {
  32.             InitializeComponent();
  33.             Random random = new Random();
  34.             foreach (object x in spMain.Children)
  35.             {
  36.                 if (x is Button button)
  37.                 {
  38.                     button.Content = Math.Floor(random.NextDouble() * 25);
  39.                 }
  40.             }
  41.         }
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment