Is it possible to set focus to a control inside the XamWebDialogWindow?
I've got a hidden XamWebDialogWindow with a TextBox in the Content template. When I set the Visibility property on the dialog to Visible I also want to set the focus to the TextBox control so the user doesn't have to click on it to enter text. I've tried calling the Focus method on both the dialog and the TextBox with no luck.
Thanks.
Hi Urfandurrani,
If you use a textbox inside a XamWebDialogWindow.ContentTemplate, it is possible to set the name of the TextBox:
="TestWin">
>
="testText"/>
it is better to use WindowState instead Visibility and when XamWebDialogWindow.WindowState=WindowState.Hidden Visibility will be Collapsed.
When change WindowState it is possible to attach to WindowStateChanged event.
Inside the event handler it is possible to add :
TextBox box = GetFrameworkElement(myWin, "myTB") as TextBox;
if (box != null)
{
box2.Focus();
}
To find element by name inside visual tree you can use a static method like that:
public static FrameworkElement GetFrameworkElement(FrameworkElement element, string ElementName)
if (element.Name.Equals(ElementName) == true) { return element; }
ContentControl control = element as ContentControl;
if (control != null)
object controlContent = control.Content;
FrameworkElement content = controlContent as FrameworkElement;
if (content != null)
FrameworkElement el = GetFrameworkElement(content, ElementName);
if (el != null) { return el; }
int numChildren = VisualTreeHelper.GetChildrenCount(element);
for (int i = 0; i < numChildren; i++)
FrameworkElement content = (FrameworkElement)VisualTreeHelper.GetChild(element, i);
return null;
I hope that this can help :-)
Kind regards!
Mihail
Hi Mihail,
Thanks for the reply. Unfortunately this didn't resolve my problem as the WindowStateChange event does not fire when I change it from Hidden to Normal.
My dialog is defined as:
<igDW:XamWebDialogWindow Grid.Row="0" Grid.RowSpan="2" x:Name="dialogCustomerSearch" WindowState="Hidden" WindowStateChanged="dialogCustomerSearch_WindowStateChanged" HorizontalAlignment="Stretch" VerticalContentAlignment="Stretch" Header="Customer Search" Height="500" Width="500" IsModal="True" StartupPosition="Center" CloseButtonVisibility="Collapsed">
<igDW:XamWebDialogWindow.ModalBackgroundEffect>
<BlurEffect Radius="10" />
</igDW:XamWebDialogWindow.ModalBackgroundEffect>
<igDW:XamWebDialogWindow.Content>
<local:orderCustomer x:Name="ctrlCustomer" Margin="5" IsTabStop="True" CustomerSelected="ctrlCustomer_CustomerSelected" SelectionCancelled="ctrlCustomer_SelectionCancelled" />
</igDW:XamWebDialogWindow.Content>
</igDW:XamWebDialogWindow>
And in code, when a button is clicked I run this (in VB.NET - sorry :-) ):
dialogCustomerSearch.WindowState = Infragistics.Silverlight.WindowState.Normal
When I do this the WindowStateChanged event is not fired. It is fired however when I close the dialog!
Am I doing something wrong?