WPF app dose not display anything after loading the main form - c#

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

Related

How to Open New Window in c# without losing xml layout

I have a c# project already working a main Window but when I created a New Window and use
Views.Form Form = new Views.Form();
Form.ShowDialog();
The page doe's open but it not showing the xml I deseigned and I think that the problem is in namespaces and derectories but havin hard time troubleshooting the proble so this is my solution explorer
Properities
References
Model
Acteur.cs
Tache.cs
ViewModels
ActeurViewModel.cs
TacheViewModel.cs
Views
Form.xaml
MainWindow.xaml
App.xaml
Model.edmx
and this is the Form Window code :
.cs file
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.Shapes;
namespace WpfApplication2.Views
{
/// <summary>
/// Interaction logic for Form.xaml
/// </summary>
public partial class Form : Window
{
public Form()
{
}
}
}
.xaml file
<Window x:Class="WpfApplication2.Form"
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:WpfApplication2"
mc:Ignorable="d"
Title="Form" Height="300" Width="300">
<Grid Background="#FF142683">
<Label Name="Test" Content="this is a test" FontSize="43"/>
</Grid>
</Window>
the MainWindow Calling
private void AddButtonClicked(object sender, RoutedEventArgs e)
{
Views.Form Form = new Views.Form();
Form.ShowDialog();
}
Have you delete the method "InitializeComponent();" in the constructor?
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
This method is created automatically by vs, and it will initialize those controls that you used in the XAML.cs.
Since you have deleted that method, that's the reason why you can not see your controls.
Just try to create a new window and you will find that method that I mentioned.

Visual Studio - WPF - References not adding properly

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>

WPF app with WebBrowser closes automatically

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

Silverlight 5.0 Custom TextBox: The Tag "TextBox" does not exist in Namespace

I am trying to write my own custom TextBox control in Silverlight 5.
I already have successfully written a custom label control, which I can reuse in my project.
The XAML and the code behind for the label control look like this.
The following code does work for me:
<sdk:Label
x:Class="Gui.CustomControls.LabelControl"
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:sw="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="125">
<Grid x:Name="LayoutRoot" Background="White">
</Grid>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace Gui.CustomControls
{
public partial class LabelControl : System.Windows.Controls.Label
{
public LabelControl()
{
InitializeComponent();
}
}
}
Now I want to do the same for a TextBox - writing my own custom TextBox Control.
The code for the TextBox looks like this: As you may see, it is nearly the same thing
<sdk:TextBox
x:Class="Gui.CustomControls.TextBoxControl"
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:sw="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="125">
<Grid x:Name="LayoutRoot" Background="White">
</Grid>
</sdk:TextBox>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace Gui.CustomControls
{
public partial class TextBoxControl : System.Windows.Controls.TextBox
{
public TextBoxControl()
{
InitializeComponent();
}
}
}
While buliding the solution the following error occurs:
"The tag 'TextBox' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk'"
As the textbox control seems to live in the System.Windows.Controls.TextBox Namespace, I tried different namespaces in the XAML, but nothing worked.
My question is:
Which namespace do I have to use, to build this custom textbox?
If it's not a namespace problem, what am I missing?
Thank you.
It's not sdk:TextBox, just TextBox (i.e. http://schemas.microsoft.com/winfx/2006/xaml/presentation, which is the default xmlns in most XAML files). While oddly not documented on the Silverlight TextBox class, this is documented on the .NET 4.5 TextBox class.

Set the corner radius of the content border

I want to have a window with the border radius of the content border is 5. Exactly like on the picture:
How can I do this With C# and WPF ? Is there any way to do this with Windows API?
WPF is rendered in standard operating system windows, if you need to change that style you have to change the so called windows chrome. The basic is to create a transparent hosting window and draw all inside it by using WPF so you can drive whatever you want and of course the corner radius too, have a look here for an example. Something more complete in this article.
If you want to search yourself, the keywords wpf custom chrome would help.
I found how to do this work :
First I needed WindowsAPICodePack, I download it from http://archive.msdn.microsoft.com/WindowsAPICodePack/
After downloading it, I Extracted it and found the necessary DLLs in /binaries folder . There are two DLLs I I needed :
Microsoft.WindowsAPICodePack.dll
Microsoft.WindowsAPICodePack.Shell.dll
Then I created an WPF Application in Visual Studio (.NET 3.5), And added these two dlls in my application
Right click on refrences in Solution Explorer tab > Add Refrence
then I changed the MainWindow XAML codes :
<WindowsAPICodePackShell:GlassWindow x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WindowsAPICodePackPresentation="clr-namespace:Microsoft.WindowsAPICodePack.Controls.WindowsPresentationFoundation;assembly=Microsoft.WindowsAPICodePack.Shell"
xmlns:WindowsAPICodePackShell="clr-namespace:Microsoft.WindowsAPICodePack.Shell;assembly=Microsoft.WindowsAPICodePack.Shell"
Title="WPF AeroGlass Demo" Height="300" Width="300" Loaded="GlassWindow_Loaded">
<Border CornerRadius="10" Background="Gray"></Border>
</WindowsAPICodePackShell:GlassWindow>
And my MainWindow.xaml.cs codes :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 Microsoft.WindowsAPICodePack.Shell;
namespace WpfApplication1
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : GlassWindow
{
public MainWindow()
{
InitializeComponent();
}
private void GlassWindow_Loaded(object sender, RoutedEventArgs e)
{
SetAeroGlassTransparency();
}
}
}
And When I run the app :

Categories

Resources