How to add content to tab items at runtime in WPF - wpf

How can I add a Web Browser control to a tabItem in WPF at runtime?

tabItem.Content = new WebBrowser();
If you want multiple controls in the TabItem, you'll need to use a Panel, just like you would in XAML.

Related

Bootstrap css style of vertical tab control for WPF?

I'm looking for a bootstrap CSS style of a vertical tab control, like at this page:
https://dbtek.github.io/bootstrap-vertical-tabs/demo.html
If I'm going to do it myself, what WPF control should I begin with as the base class? (I don't think the WPF tabcontrol should be a starting point because the styles are so different)
Thanks
You can re-style the TabControl and the TabItems to look like you want. It may require some effort though.
You can right-click on a TabControl in design mode in Visual Studio or in Blend and choose Edit Template->Edit a Copy to copy the default style into your XAML markup and then edit it as per your requirements. Edit Additional Templates->Edit Generated Item Container (ItemContainerStyle) will do the same thing for the TabItem container.
Also note that you can set the TabStripPlacement property of the TabControl to Left to change the position of the tabs.

Can I add an ElementHost to a regular WinForm StatusStrip?

I just started learning WPF, and I've been trying to add this WPF control to a regular WinForm.
I know I can use Forms.Integration.ElementHost to host WPF controls in a WinForm. But as StatusStrip takes Items and not Controls it's marking the ElementHost as incompatible.
Do I need to replace the entire StatusStrip with WPF ToolBar for this to work?
You can use ToolStripControlHost to add any control to the strip. For example for an element host which hosts a wpf user control, you can use this code:
var host = new ToolStripControlHost(this.elementHost1);
this.statusStrip1.Items.Add(host);

Choose Correct Control (TabControl,ListView,ListBox,Button) - WPF Custom Style

I want to create a theme like Apple Ipad in WPF,
if you know any , please let me know.
else, please help, to choose correct control for these Pictures in WPF (TabControl,ListView,ListBox,Button).
Thank you.
as for the top picture, it makes sense to use a TabControl where you need to:
change the template/style of the TabControl to center the TabItem headers. you can change the panel to just a StackPanel with Horizontal orientation or a custom panel.
as for the TabItem controls, you make the round corners of the first and last items by setting the attached properties IsFirst, IsLast (you need to create them).
the attached properties can be set either automatically by the custom panel, or manually via xaml.
Regards

How to override the selected item style of MahApps Panorama Control?

I am using the MahApps Panorama Control in my project by linking the Mahapps.Metro.dll so I can't change the XAML-Code of the Panorama Control directly.
I thought it would be possible to override values in my MainWindow.xaml but when I do so nothing changes or maybe I change the wrong property.
The problem with the Panorama Control is that the selected item has a white border and I can't find a way to remove this selection style. I tried several solutions like changing the style or changing the control template (How to disable highlighting on listbox but keep selection?) but my changes have no influence of the Panorama Control.
There you can see the Panorama Control XAML.
This is an issue with the way that the Styles are inherited, and it's tricky to see how the ListViewItems and ListBoxItems work together. I fixed this by inserting the following in the code behind. It does, however, lose your selected item:
var listbox = MyPanorama.FindChildByType<ListBox>();
if (listbox != null)
{
listbox.SelectedIndex = -1;
}
FindChildByType is a simple search to return the first ListBox that is found under the Panorama. If you have a search by name the x:Name of the template listbox is "items".

WPF Custom control template

I have made one custom user control (search text box), which basically consists of one dock panel, and in the panel there are two controls: textbox and button.
I have set some default appearance for this control, which consists of setting a border on the user control, and setting no borders and no background on the textbox, and I have created a custom style for the button. So far this control looks the way I want, and is working correctly.
The problem arises when I want to allow themes for my application. When I put custom styles for basic windows controls (Button, TextBox, ListBox, etc), they are displayed properly with the new theme. But I don't know how to make a template for my custom control. Any attempt ended up in the control not showing at all at runtime.
What exactly must be done in the new template for this control? Do I need to make a template for the User control, and for the textbox and the button controls also?
You are mixing up user controls and custom controls here. What you described above is a user control, and you cannot apply new templates to it.

Resources