Load .xaml page into textbox in wpf - c#

Hi I have a problem with loading .xaml page to textbox located in MainWindow. In previous implementation I used tabs, so I could simply write something like this
<TabItem Header="First Tab" Name="firstTab">
<Frame Background="White" Name="firstTabFrame" Source="Tabs/firstTab.xaml/>
</TabItem>
Which propably handled enabled to load firstTab.xaml into mainPage.
Now I have a Ribbon in which I have some kind of groups etc. How to load page firstTab.xaml into my mainPage (maybe to textbox? grid?) after clicking RibbonMenuButton clicked.

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();

call to page inside tab control via code

I heed to create wizard and in the wizard I have tab control which have to call to the user control according to the context,I need to create the wizard which will able to invoke
different pages according to the user selection ,currently I call to the pages as follows which I think is not the right way,any Idea how should I do it via code (not in the xaml )i.e. according to some decision invoke the suitable page to the tab control.
this is the xaml:
<Border Grid.Column="1" Name="MainBorder">
<TabControl x:Name="MainTabControl" Height="638" VerticalAlignment="Bottom">
<TabItem Visibility="Collapsed" >
<Frame Source="page1.xaml" />
</TabItem>
<TabItem Visibility="Collapsed" >
<Frame Source="page2.xaml"/>
</TabItem>
<TabItem Visibility="Collapsed" Header="Step 3">
<TextBlock Text="Page 3"/>
</TabItem>
<TabItem Visibility="Collapsed" Header="Step 4">
<TextBlock Text="Page 4"/>
</TabItem>
</TabControl>
</Border>
UPDATE
I was tried in the main window like the following without success
create new tab by code and add to it the page 1 and then add it to the MainTabControl
TabControl tabControl = new TabControl(new Page1());
MainTabControl.add..
.
there is no add in the main tab control
For this scenario, I would use a Frame rather that tabs. The frame allows you to manage the flow of it's content via the NavigationService. You can use Uri's to display a page via the Frame.Source property, or a FrameworkElement via the Frame.Content property. Both are DependencyProperties and can therefore be bound to.
Paul Stovel wrote an excellent blog on this called WPF Navigation. Everything you need to create a wizard from a frame can be found in this blog, including passing values between pages and templating of the Frame to simply handle the display of navigation buttons.
I would agree with Mark, it is a lot easier to use NavigationWindows than TabControls.
I've worked on a lot of interfaces like this and written up some of the basic things with,
WPF Wizards, Part 1
WPF Wizards, Part 2
Then more recently I worked out how to get the styling just right
Styling Wizards
In fact I've released the styling and examples as open source at
WinChrome
There is some simple example code including use of a navigation list to the left with,
WinChrome.Win7Demo
Hope this helps

Silverlight RadComboBox Dropdown stays open even when not in focus

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,

How to manage code in multitab application?

I'm making application in .NET C#.
It is not my choice but it has to be "multi-tab" application.
I have one window with tab control with many tabs.
There are many controls on every tab. Now all my event handlers and stuff is in main window file.
How to manage this program.
Is there any way to keep content of every tab in separate file (maybe class)?
Can use a frame and reference a page or user control
<TabControl>
<TabItem Header="Tab1 Page">
<Frame Source="TabPage.xaml" NavigationUIVisibility="Hidden" />
</TabItem>
<TabItem Header="Tab2 User Control">
<Frame Source="UserControl1Tab.xaml" />
</TabItem>
</TabControl>
A User Control is probably cleaner but I use Page out of habit.
They both have code behind for event handlers.
If you need to pass data then can do it in the ctor (but then you cannot assign the Source in XAML).

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