I want to create a button that moves the activecell to the next one.
I tried using the MoveFocus method, but it does not seem to work.
How Can I do this ?
Hello,
I am very glad that this method is helpful for you. Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Thank you. It works better with this.
I am very glad that the approach I suggested is helpful for you. When using the GetDescendantFromType method, you will get the first element from type T which is in the visual tree of first parameter of the method. I have created a method for you that will allows you to get all elements from given type in the visual tree of an element. Here is the method and how can be used:
Xaml:
<Window x:Class="GetAllChildrenFromTypeTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Button Content="Button" Height="75" Name="button1" Width="75" Click="button1_Click"> <Button.Template> <ControlTemplate TargetType="Button"> <Grid Background="Green"> <StackPanel> <ContentPresenter Content="{TemplateBinding Content}"/> <ContentPresenter Content="{TemplateBinding Content}"/> <ContentPresenter Content="{TemplateBinding Content}"/> <ContentPresenter Content="{TemplateBinding Content}"/> </StackPanel> </Grid> </ControlTemplate> </Button.Template> </Button> </Grid> </Window>
C#:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { List<ContentPresenter> elements = new List<ContentPresenter>(); GetAllChildrenFromType(sender as DependencyObject, elements); } private void GetAllChildrenFromType<T>(DependencyObject parent, List<T> elements) where T : DependencyObject { if (elements == null) elements = new List<T>(); for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) { if (VisualTreeHelper.GetChild(parent, i) is T) { elements.Add(VisualTreeHelper.GetChild(parent, i) as T); } else { GetAllChildrenFromType<T>(VisualTreeHelper.GetChild(parent, i), elements); } } } }
Please let me know if you need any further assistance on the matter.
Thank you, I think I will be able to work with this (I did some tests).
Just another question : GetDescendantFromType returns only one object.
What if there is many descendants from the type for an element ?
Is there a way to get them all ?
I am just checking your progress on the issue.
If you require any further assistance please do not hesitate to ask.