Пример #1
0
 public MainWindow()
 {
     InitializeComponent();
     MyAttachedPropertyProvider.SetMyProperty(FirstButton, 44);
     foreach (FrameworkElement item in LogicalTreeHelper.GetChildren(MainGrid).OfType <FrameworkElement>().Where(item => item != null))
     {
         SingleListBox.Items.Add(string.Format("{0}: {1}", item.Name, MyAttachedPropertyProvider.GetMyProperty(item)));
     }
 }
        private void OnButton8_click(object sender, RoutedEventArgs e)
        {
            foreach (var item in LogicalTreeHelper.GetChildren(grid1).OfType <FrameworkElement>().Where(u => MyAttachedPropertyProvider.GetMySample(u) != string.Empty))
            {
                listbox1.Items.Add($"{item.Name}:{MyAttachedPropertyProvider.GetMySample(item)}");
            }

            foreach (var item in GetChildren(grid1, u => true).Where(m => MyAttachedPropertyProvider.GetMySample(m) != string.Empty))
            {
                listbox1.Items.Add($"{item.Name}:{MyAttachedPropertyProvider.GetMySample(item)}");
            }

            foreach (var item in GetChildren(grid1, u => MyAttachedPropertyProvider.GetMySample(u) != string.Empty))
            {
                listbox1.Items.Add($"{item.Name}:{MyAttachedPropertyProvider.GetMySample(item)}");
            }


            foreach (var item in GetChildren(grid1, u => { return(!string.IsNullOrEmpty(MyAttachedPropertyProvider.GetMySample(u))); }))
            {
                listbox1.Items.Add($"{item.Name}:{MyAttachedPropertyProvider.GetMySample(item)}");
            }
        }
        private void OnButton7_Click(object sender, RoutedEventArgs e)
        {
            var str = MyAttachedPropertyProvider.GetMySample((Button)sender);

            MessageBox.Show(str);
        }
        public MainWindow()
        {
            InitializeComponent();

            MyAttachedPropertyProvider.SetMySample(button5, "btn5");
        }