I need a little kickstart for creating a Visual Studio "Startpage" in the Version 2015.
There are old information (https://msdn.microsoft.com/en-us/library/Ee663382(v=vs.120).aspx) out there and some projects on Visual Studio Galery (eg "BetterStartPage" or "SolutionStartPage". Expecialy the "Custom Start Page Project Template" is out of date :-(
I do start a project with this tutorial: https://msdn.microsoft.com/en-us/library/ff425532(v=vs.140).aspx
But the steps and the information are quite ... short.
Here is my problem:
I compile the Custom Control Library project and following the manual installation steps mention in the article. I can select my custom start page, but it doesn't start my custom contol. The page is just empty. Its like the code in the DLL is not executed.
Here is the test-XAML file:
<UserControl
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:MyNamespace="clr-namespace:StartPageControl;assembly=StartPageControl"
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns:MeineControls="clr-namespace:StartPageControl"
xmlns:local="clr-namespace:StartPageControl"
x:Class="StartPageControl.UserControl1"
mc:Ignorable="d"
Height="350" Width="525">
<Grid>
<Grid x:Name="LayoutGrid" >
<Button Click="Button_Click" Content="push me" Foreground="black" />
<Label x:Name="label" Content="Label" HorizontalAlignment="Left" Margin="720,171,-295,0" VerticalAlignment="Top" Width="100"/>
</Grid>
</Grid>
</UserControl>
UserControl1.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace StartPageControl
{
/// <summary>
/// Interaktionslogik für UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl {
public UserControl1()
{
InitializeComponent();
ButtonApp ButtonApp1 = new ButtonApp();
LayoutGrid.Children.Add(ButtonApp1 as UIElement);
}
private void Button_Click(object sender, RoutedEventArgs e) {
label.Content = "Something happend!";
}
}
}
EDIT:
Here are the steps I did:
Creating a new WPF Control Libraby Project
Add a new XAML and add/change the namespaces
Add some "code behind" eg a Button with a Click-Event
Compile
Copy the XAML file in %USERPROFILE%\My Documents\Visual Studio 2015\StartPages\
Copy the Project .DLL in \Common7\IDE\PrivateAssemblies\
Start a new VS and choose the new Startpage
Getting the error (translated from german):
"System.Windows.Markup.XamlParseException" ... "Error creating 'Click' from Text 'Button_Click'"
..so I tried to use a UserControl in a UserControl (as you can see in the code above). There comes the the message "{clr-namespace:StartPageControl}ButtonApp can not be created"
:-( It seems to me, VS don't use the "Code Behind"/DLL...
I know it's a kind of diffuse question. Knows anybody a better startingpoint?
EDIT 2:
Paste all the Test-Code.
Related
I have a most concise WPF program. The XAML interface is as follows. The code does not contain any other non automatically generated conten
enter image description here
He runs normally on my own computer, and the interface is as follows
enter image description here
But when I start this program on the client's computer, nothing is displayed
enter image description here
I use .NET Fremwork 4.8. The target platform uses x64. In order to prevent the problem of .NET, I use the same .Net framework generates a WinForms application. Its behavior and display are normal on the client computer, so I suspect this is a WPF problem
Do you have any similar problems and solutions
This is all the code
MainWindow.xaml
<Window x:Class="NET48TEST.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:NET48TEST"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Label Content="此电脑可以运行有.NET 4.8框架开发的应用程序"/>
</Grid>
</Window>
MainWindow.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace NET48TEST
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
Maybe you can try:
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
How are you running the client, release or debug mode?
try putting a background to the label and centralized
Am new to oxyplot and wish to use it with C# WPF with xaml. My .xaml file has the following code:
<code>
<Window x:Class="CurveMaster.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:CurveMaster"
xmlns:oxy="http://oxyplot.org/wpf"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<Grid>
<oxy:Plot Title="{Binding Title}">
<oxy:Plot.Series>
<oxy:LineSeries ItemsSource="{Binding Points}"/>
</oxy:Plot.Series>
</oxy:Plot>
</Grid>
</Window>
</code>
The .xaml.cs file is as follows:
<code>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OxyPlot;
namespace CurveMaster
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public class MainViewModel
{
public MainViewModel() //Constructor
{
this.Title = "My Graph";
this.Points = new List<DataPoint>
{
new DataPoint (0,4),
new DataPoint (10,13),
new DataPoint (20,15),
};
}
public string Title { get; private set; }
public IList <DataPoint> Points { get; private set; }
}
}
</code>
So I'm just trying to run the above simple example but get the following error messages in the xaml file:
The type 'oxy:Plot' was not found. Verify that you are not missing an assembly reference.
The name "MainViewModel" does not exist in the namespace "clr-namespace:CurveMaster".
Now I installed the oxyplot Nuget package for WPF and installation was successful. However, above tells me that the above two issues are both referencing issues but I cannot figure out what the problem is. What additional oxyplot referencing is required once the package is installed?
Secondly why does it give me the MainViewModel does not exist message when in fact it does exist in the CurveMaster namespace?
Thanks in advance.
If you (or someone else) still needs the answer - thats what helped me.
I also tried to install OxyPlot from Nuget and it gave referencing and non-existing errors. So I finally overpowered it with:
I have downloaded oxyplot from github, built it and took necessary DLL manually into my solution (OxyPlot.dll, OxyPlot.wpf.dll, OxyPlot.wpf.shared.dll)
I have changed
xmlns:oxy="http://oxyplot.codeplex.com"
to
xmlns:oxy="http://oxyplot.org/wpf"
in XAML.
I have looked through past questions on this issue to no avail.
I've just created a new WPF project in VS 2013. I go to Add Reference, and select System.Windows.Form. It adds. Great!
However, the appropriate tools are still greyed out in the toolbox. Yes, auto-update toolbox is on. I've shown all. I've restarted VS and rebuilt my solution. I've added using System.Windows.Forms; to my MainWindow.xaml.cs file.
At this, I only have the bare bones code because this is a completely new project that I haven't touched yet.
What am I missing?? I've tried dragging the .dll file to the toolbox, tools are still greyed. Is there a piece of code I'm missing somewhere?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
namespace sub20tool3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
And:
<Window x:Class="sub20tool3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:local="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
You need a WindowsFormHost element to hold winforms controls in a WPF project. The WindowsFormHost also needs a reference to WindowsFormIntegration.
Here's a good tutorial on how to use them: http://www.wpf-tutorial.com/misc-controls/the-windowsformshost-control/
<Window x:Class="WpfTutorialSamples.Misc_controls.WindowsFormsHostSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="WindowsFormsHostSample" Height="350" Width="450">
<Grid>
<WindowsFormsHost Name="wfhSample">
<WindowsFormsHost.Child>
<wf:WebBrowser DocumentTitleChanged="wbWinForms_DocumentTitleChanged" />
</WindowsFormsHost.Child>
</WindowsFormsHost>
</Grid>
</Window>
What I am trying to do is have a webview on the blank page generated by a template for the Windows Store. Then when I click a button, it changes the page that the webview is currently on. The problem is, I do not know how to access the XAML variable from the codebehind to change it.
<Page
x:Class="App6.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App6"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<WebView x:Name="browser" Source="https://www.google.com/" HorizontalAlignment="Left" Height="224" Margin="463,237,0,0" VerticalAlignment="Top" Width="570"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="224,110,0,0" VerticalAlignment="Top"/>
</Grid>
I've tried accessing the name browser in the C# code. But Visual Studio can't find it. I've looked around for a little bit but there weren't many examples that I could find that had this....
I've tried to open this (http://code.msdn.microsoft.com/windowsapps/XAML-WebView-control-sample-58ad63f7) for an example of how to use it. But this will not build, or open with Visual Studio 2013..
code behind it
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/? LinkId=234238
namespace App6
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
}
Do something like
private void Button_Click(object sender, RoutedEventArgs e)
{
browser.Navigate(new Uri(#"www.microsoft.com"));
}
Where browser is your actual control WebView.
I need to add WebBrowser control to WPF form.
I have the easiest code:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
<WebBrowser HorizontalAlignment="Left" Height="279" Margin="10,10,0,0" Name="wb1" VerticalAlignment="Top" Width="461">
</WebBrowser>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
string url = "http://www.microsoft.com";
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
wb1.Source = new Uri(url);
}
}
}
but application is closing automatically navigate to page. Why?
I see the following strings on output code:
The program '[4892] WpfApplication5.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[4892] WpfApplication5.vshost.exe: Managed (v4.0.30319)' has exited with code -1073740791 (0xc0000409).
I fixed this problem (but only for Visual Studio 2010, project under Visual Studio 2013 has error) - I have changed "Target Platform" from x86 to "Any CPU". Strange, but works