Windows Forms Chart Collection Editors in WPF - c#

I am a new WPF user, coming from Windows Forms and I have a question regarding Windows Forms Control Integration in WPF.
Windows Forms offer a very extensive built-in Data Visualization Chart control, which I would like to use in a WPF application.
I successfully added the chart control to the application, using a WindowsFormsHost control. This is how the XAML code looks:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:winformchart="clr-namespace:System.Windows.Forms.DataVisualization.Charting;assembly=System.Windows.Forms.DataVisualization"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Name="mainWindow" x:Class="WPFChartControl.MainWindow"
Title="WPF Chart Control" Height="350" Width="525" WindowStartupLocation="CenterScreen">
<Grid d:IsLocked="True">
<WindowsFormsHost x:Name="chartHost" HorizontalAlignment="Left" Height="260" Margin="10,10,0,0" VerticalAlignment="Top" Width="497" d:IsLocked="True">
<winformchart:Chart x:Name="MyChart" Dock="Fill">
<winformchart:Chart.Series>
<winformchart:Series Name="series" ChartType="Line"/>
</winformchart:Chart.Series>
<winformchart:Chart.ChartAreas>
<winformchart:ChartArea/>
</winformchart:Chart.ChartAreas>
</winformchart:Chart>
</WindowsFormsHost>
<Button Content="Add Point" Click ="Button_Click" Margin="221,275,221,0" VerticalAlignment="Top" d:IsLocked="True"/>
</Grid>
</Window>
And now my question: Is there any way to access the Chart Collection Editors (Annotations, ChartArea, Legends, Series, Titles) from Visual Studio's Property window at design time, similar to how they can be accessed when developing Windows Forms applications? I find these editors very convenient to use, compared to customizing all the chart properties from code.
Windows Forms Properties
ChartArea Collection Editor

Related

WindowChrome is not supported in a WPF project

I'm brand new to WPF after using WinForms for years. I'm trying to get a window that looks like a typical windows form with the blue border and red close button, or really anything that has a border like it shows in the middle 2 windows of the Microsoft Docs. This is for .Net framework up to 4.8.1 but I am using .net 6.
but my app always shows with no border:
Here is my MainWindow.xaml:
<Window x:Class="Sim.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Sim"
mc:Ignorable="d"
Title="Simulator" Height="650" Width="1000"
Icon="Resources/Sim.ico"
WindowStyle="SingleBorderWindow">
<Grid>
<Button x:Name="Power" Content="Power" HorizontalAlignment="Left" Margin="84,84,0,0" VerticalAlignment="Top" Click="OnPowerClick"/>
</Grid>
</Window>
I tried to add WindowChrome after WindowStyle="SingleBorderWindow">
<Setter Property="shell:WindowChrome.WindowChrome">
</Setter>
but I get the error "WindowChrome is not supported in a Windows Presentation Foundation (WPF) project."
Is there a way to get an older style border in .net 6 wpf?

Problem With Hotbar, arrow as web site in .net framework wpf app

Image with Problem
This is a WPF application launched with debug of visual studio
I've a window, where show content
<Window x:Class="Test.All"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Test"
mc:Ignorable="d"
Title="All" Height="450" Width="800">
<Grid>
</Grid>
and a user control, with the content to show in the window
<UserControl x:Class="Test.ShowContent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Test"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Button x:Name="btnrand" Content="button" HorizontalAlignment="Left" Margin="300,69,0,0" VerticalAlignment="Top" Width="200" RenderTransformOrigin="0.473,0.477" Height="58" Click="btnrand_Click"/>
<Label x:Name="showblasph" Content="" HorizontalAlignment="Left" Margin="60,169,0,0" VerticalAlignment="Top" Height="163" Width="664" FontSize="24"/>
</Grid>
</UserControl>
With a WinForms application, I did not have that problem, but with wpf yes, any ideas?
The problem is the arrows at the top
You are accidentially using a NavigationWindow instead of a Window. A navigation window has built-in browser-like controls. These controls are not shown in the Visual Studio designer, but at runtime. The black bar at the top are the XAML debugging tools, that you can enable or disable in debug mode.
A navigation window is used automatically, if you specify a UserControl resource as StartupUri. What type of window is used or created depending on the startup URI is documented here.
Types that display a NavigationWindow when set as StartupUri resource:
NavigationWindow
Page
UserControl
FlowDocument
PageFunction<T>
Therefore, you have to set a Window as StartupUri and set its Content to your UserControl.

WPF form application doesn't have the same properties as in the designer

I'm learning how to create wpf controls (and windows) with Visual Studio 2019. As a first step, I've tried to generate a Window with a label inside. Using the following code, it looks like this (designer window)
<Window x:Name="Ventana" x:Class="PhanUtils.Sistema.Recursos.Ventanas.Mensaje"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:PhanUtils.Sistema.Recursos.Ventanas"
Width="580" Height="175" MinWidth="580" MinHeight="175" MaxWidth="580" MaxHeight="175"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
HorizontalAlignment="Center">
<Grid>
<Label x:Name="L_Informacion" Content="Label" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="554" Height="126" BorderBrush="#FFCF1E1E" BorderThickness="5"/>
</Grid>
</Window>
However, when I run the application and I show the same dialog, it looks like this:
Does anybody know why I'm having this issue?

How to integrate Prism 7 WPF into old, large WinForms App

I am attempting to integrate a (Prism 7) WPF Window into an existing WinForms app.
My window is defined as:
<Window x:Class="ESC.SV.UI.RAndDClient.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ESC.SV.UI.RAndDClient"
xmlns:core="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:prism="http://www.codeplex.com/prism"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
Title="{Binding Title}" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<dxb:BarContainerControl Grid.Row="0">
<dxb:ToolBarControl Caption="Main Toolbar" BarItemHorizontalIndent="10">
<dxb:BarButtonItem Content="View 1" Glyph="{dx:DXImage Image=Forward_16x16.png}" Command="{Binding ExecuteView1Command}"/>
<dxb:BarButtonItem Content="View 2" Glyph="{dx:DXImage Image=Backward_16x16.png}" Command="{Binding ExecuteView2Command}"/>
</dxb:ToolBarControl>
</dxb:BarContainerControl>
<ContentControl prism:RegionManager.RegionName="ViewsRegion" Grid.Row="1" VerticalAlignment="Top"/>
</Grid>
When I launch the WinForms app and go to show this window, I get the following error message:
... which explains to override ConfigureRegionAdapterMappings method in the bootstrapper, but when I go to create a BootStrapper class that inherits from UnityBootstrapper, it says that this is now obsolete. I know that App is supposed to inherit from PrismApplication, but does this apply to a WinForms application as well?
Any advice on how to deal with this situation is greatly appreciated.
I know that App is supposed to inherit from PrismApplication, but does this apply to a WinForms application as well?
Prism is a WPF-application framework (and UWP and Xamarin). It does not support WinForms. That being said, you can use parts of Prism individually, of course, even without any GUI (the event aggregator, for example, would work fine in a windows service).
What do you want to use from the prism library? Basically, for each feature, you have to look what the bootstrapper does to initialize and configure it and then adapt that initialization and configuration to your app.

Is there a way to display WPF Extended Toolkit's control in VS Designer?

I'm used to create my forms with the designer, and modifying the XAML manually only when needed.
Even though the extended toolkit is a fantastic library, it still lacks integration with Visual Studio's designer. Can, by any mean, the toolkit's controls be displayed in the designer (not the toolbox), like standard controls? And if not, is there an explanation?
For now, the toolkit's controls are just blank and unselectable with simple clicks.
NOTE: It seems that the issue happens with container components (like BusyIndicator and Wizard/WizardPage) only.
EDIT: Here's some of my XAML. With this, I can see the wizard's first page, but no obvious way to see the others. If I put my Wizard in a BusyIndicator, can't see a thing at all.
<Window x:Class="MyProgram.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyProgram"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
Title="My Program" Height="477" Width="688" MinWidth="688" MinHeight="478">
<xctk:Wizard x:Name="wizard" FinishButtonClosesWindow="True" Next="wizard_Next">
<xctk:WizardPage Name="Intro_Page" Title="ABC" Description="abc" NextPage="{Binding ElementName=Second_Page}" Enter="disallowNext">
<xctk:WizardPage.Content>
<Grid>
<Label Content="abc" HorizontalAlignment="Center" Margin="0,54,0,87" Name="intro_lbl" VerticalAlignment="Center" Grid.Column="1" Padding="5" HorizontalContentAlignment="Center" Height="28" IsEnabled="False" />
</Grid>
</xctk:WizardPage.Content>
</xctk:WizardPage>
<xctk:WizardPage Name="Second_Page" Title="DFG" Description="dfg" NextPage="{Binding ElementName=Last_Page}">
<xctk:WizardPage.Content>
<Grid Name="grid">
<TextBox Grid.Column="1" Height="23" HorizontalAlignment="Stretch" Name="txt_second" VerticalAlignment="Center" />
</Grid>
</xctk:WizardPage.Content>
</xctk:WizardPage>
<xctk:WizardPage Name="Last_Page" PageType="Interior"
Title="Last Page"
Description="This is the last page in the process"
CanFinish="True" />
</xctk:Wizard>
</Window>
I know this answer comes late, but yesterday I was stumbling myself over this problem and maybe it is useful for others who land here.
I solved it by creating an own control derived from WizardPage.
Just Create a new UserControl, include the Xceed.Wpf.Toolkit namespace and change the Type from UserControl to xctk:WizardPage in the xaml file as well as in the code-behind file.
<xctk:WizardPage x:Class="WizardTest.MyWizardPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
xmlns:local="clr-namespace:WizardTest"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock>Hello World!</TextBlock>
</Grid>
</xctk:WizardPage>
Now you can create your UI using the VisualStudio Designer.
To place your page in the wizard, simply put an object of you derived page into its items:
<xctk:Wizard>
<local:MyWizardPage Title="My Wizard Page"/>
</xctk:Wizard>
You can use Bindungs in your costum page out of the box because DataContext of the MyWizardPage object is set automatically to the wizards DataContext (which inherits from the Window DataContext if not explicitly given)

Categories