Silverlight RadComboBox Dropdown stays open even when not in focus - c#

I have a user control that contains a scroll viewer. inside the scroll viewer I placed another user control with grid, and inside the grid there is a combo box.
all this is placed inside a RadWindow.
Something like this:
first user control: (displayed inside a RadWindow)
<UserControl x:class = "MyFirstUserControl">
<Grid>
<ScrollViewer>
<StackPanel x:Name="stackPanel"/>
</ScrollViewer>
</Grid>
</UserControl>
second user control:
<UserControl x:class = "MySecondUserControl">
<Grid>
<telerik:RadComboBox x:Name = "comboBox"/>
</Grid>
</UserControl>
in code behind I add the second user control to the stackPanel:
stackPanel.Children.Add(new MySecondUserControl());
Now, the problem is: when the combo-box drop down is open, and I scroll up / down the control - I expect it to close, but- it remains open...
I try to catch the MouseLeftButtonUp event of the scroll bar, and set the IsDropDownOpen of the comboBox to false, but it is false nonetheless and the drop-down still open.
How can I force the drop-down to close when focus is not on it, even if the focus is out of the combo control altogether?
Thanks,

Related

Container in mainWindow XAML to display user controls

I am trying to create a main window with buttons on the right and when a button is clicked a different user control screen should show on the left side. When creating the main XAML , what can be used as a container for the user controls to display in?
I Used a TabControl in a ScrollViewer as the container in a column of the Grid.
<ScrollViewer Grid.Column="1">
<TabControl x:Name="Container" >
</TabControl>
</ScrollViewer>
This was the code I needed to change on button click:
Container.Items.Clear();
var login = new UserRegisterUserControl();
Container.Items.Add(login);
Container.Items.Refresh();

WPF Checkbox - Clicking label does not change checked state

I have a CheckBox in a TabItem Header in a WPF application. I am finding that when you click on the TabItem, it is checking the CheckBox, but not opening the TabItem. I would like only the actual CheckBox to register the click event to change the state from Checked to Unchecked or vice versa. That way, clicking on the label of the CheckBox will open the TabItem.
I've tried using an empty CheckBox that has no content and then a separate Label adjacent to it, but then the TabItem tells me that it cannot have 2 headers.
<TabItem>
<TabItem.Header>
<CheckBox Name="chkExportEnabled" Content="{x:Static resources:Global.Label_Export}" IsChecked="{Binding EnableExport}"/>
</TabItem.Header>
</TabItem>
You can just use a StackPanel with Orientation='Horizontal' around the label-less CheckBox and the Label. TabItem.Header may only contain a single child, that's why you get the error, but nothing prevents you from using layout containers as that child.

User Control Visibility

I have a WPF form in which I have 4 user controls within a tab control. I change the visibility of the user control as i move forward. For eg: UC1 visible is true, UC2,UC3,U4 : visibility is false then onlick of a next button in UC1, UC1 becomes visible false and UC3 visible true.And so on.
<TabControl HorizontalAlignment="Left" >
<TabItem Header="Test">
<StackPanel Orientation="Horizontal" >
<View:UC1 />
<View:UC2 />
<View:UC3 />
</StackPanel>
</TabItem>
</TabControl>
UC1 and Uc2 works,However when i make uc3 visible the control moves far right and there is space in between. I dont get what i am doing wrong here.
If there is some space between the control and you can see nothing. That means that there is something present. Either it is
Padding
Margin
Hidden Control.
To minimize this, you should use the Collapsed property of the Visibility.
Use this,
Visibility = Visibility.Collapsed;
for your UC3 element. It would be like, there is no such control between the controls.

Get item's object for the dropped gridview Grid

I have a GridView with a custom template. I want the user to be able to drop some of items on another items. I enabled the drag & drop and added the drop handler to the Grid which is used for item's template:
<GridView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Left" Width="250" Height="250" AllowDrop="True" Drop="content_Drop">
With the code above, I'm able to handle which Grid the user has dropped the item onto. However, I'm not able to get the object for this Grid. A trick (using an invisible control and lookup) comes to my mind but I'm looking for a better way.
The DataContext property of the Grid will be set to the item bound to that ItemTemplate.

WPF losing data in previous page when a new page is created in Navigation window

I have an app which uses the navigation window. THe page is designed this way.
<Page>
<Grid>
<ComboBox/> <TextBox/>
<Grid> <TextBox/> </Grid>
<Grid> <TextBox/> </Grid>
<ListBox/>
</Grid>
</Page>
Now when i click a "new", i create a page,
Page1 pg1 = new Page1();
this.NavigationService.Navigate(pg1);
Now when i come back to the previous page, i lose the items in the listbox and the text in those two textboxes within the grid. The text in the combobox and textbox remains as selected/typed. How do i keep the data in the page as it is?
Thanks
Set KeepAlive property of the element to "True"
WPF unloads its controls if they are not visible. I am guessing that the items in your listboxes and textboxes are not bound to anything so they get reset when the controls get reloaded.
Best way to avoid that is to bind them to something in the code behind so that they maintain their data.

Categories

Resources