Edit Xaml files on debuging Visual studio 2019, WPF - c#

I want to Edit UI XAML files with my program running and see these changes without to stop my program...
When I change these files right now It just o nothing until I close my program and start again.
For exmaple:
this is my xaml code:
<Window x:Class="WpfApp4.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:WpfApp4"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>
http://prntscr.com/nwiw0o
I see an empty white screen
When I change it (on debug) to
<Window x:Class="WpfApp4.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:WpfApp4"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Background="Blue">
<Grid>
</Grid>
</Window>
http://prntscr.com/nwiw7q
Nothing is change
But when I restart my program
It runs this blue screen...
http://prntscr.com/nwiwiw
I think its something about debugging option?
this is my page open list
http://prntscr.com/nwiwtu

You probably don't have "Edit and continue" enabled, because you can just edit xaml and see the result immediately if you do.
From the Debug menu, choose Options.
On the left Debugging should be selected for you and the default will be the first option - General. If that isn't selected, do so.
Scroll the right panel down.
Tick the Enable UI debugging tools for XAML and at least Enable XAML Edit and Continue.
You should then be able to change simple properties in XAML and see your changes reflected immediately in the running UI. It does not work for everything though.
https://devblogs.microsoft.com/visualstudio/ui-development-made-easier-with-xaml-edit-continue/

Related

Adding Icon property to xaml

I'm trying to add an icon to a wpf window, but I'm getting an xaml parsing exception whenever I add the following line to my code:
Icon="myIcon.ico"
My window tag looks like this (and runs fine) without the Icon property:
<Window x:Class="MyProject.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:MyProject"
mc:Ignorable="d"
Title="My Project" Height="562.356" Width="1058.204">
If I add Icon="myIcon.ico" before the >, I get an error on the W in Width="1058.204"
Exception thrown: 'System.Windows.Markup.XamlParseException' in
PresentationFramework.dll
Additional information: 'Provide value on
'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an
exception.' Line number '8' and line position '58'.
So, the code erroring out looks like this:
<Window x:Class="MyProject.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:MyProject"
mc:Ignorable="d"
Title="My Project" Height="562.356" Width="1058.204"
Icon="myIcon.ico">
I feel like I must be missing something very simple here. Based off of other posts here (How to change title bar image in WPF Window?) I feel like I'm doing it right.
Can anyone help? Thanks!
I solved this with a little bit of help from m.rogalski's suggestion and using information in here:How to reference image resources in XAML?
After importing my image to the project, I changed my code to look like this, and it worked:
<Window x:Class="MyProject.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:MyProject"
mc:Ignorable="d"
Title="My Project" Height="562.356" Width="1058.204"
Icon="pack://application:,,,/my folder/myIcon.ico">
If I add Icon="myIcon.ico" before the >, I get an error on the W in Width="1058.204"
Add the myIcon.ico file to your project and set its Build Action property to Resource in the properties pane in Visual Studio.
You can then either set the Icon property of the window to a relative URI or a pack URI or you could specify the the icon as the default icon of your application under Project->Properties->Application->Icon and manifest.

how to set header for change place of app window

i made a wpf app and set the WindowStyle to None
but
when i cant change the place of app
and
is there any other way to change the size of app without set ResizeMode to CanResizeWithGrip?
<Window x:Class="WpfApplication1.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:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="358.685" Width="542.37"
ResizeMode="CanResizeWithGrip" WindowStartupLocation="CenterScreen"
WindowStyle="None" AllowsTransparency="True" Background="White">
</Window>
If I understood correctly you want to re size your main window in code.
You can do this anywhere in code by using the following:
App.Current.MainWindow.Width = 500;
App.Current.MainWindow.Height = 500;
where of course you can substitute 500 with whatever size you want.

UserControl content can't be set more than once

having some troubles with UserControl. I cannot get rid of "Content is set more than once error"
From what I've read, the common cause is that .. well, content is set more than once. For example having more than one child or setting content via Content=".." and then specifying another content between the tags.
However, this is UserControl generated by VisualStudio and I made no changes to the xaml.
<UserControl x:Class="TMEGadget.View.Toolbox"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>
Got any tips?
P.S: Can anyone tell me why, when I try to type "Hey,\n\nSome text...", the "Hey,\n\n" is deleted?
Edit: Restarting VS fixed the problem , thanks #Bolu

Can't access Windows 8 Store user control from code

I'm writing a Windows 8 Store application and within that I've designed my own user control.
Here is the code for my usercontrol (This is a dummy control but the problem exists with this):
<UserControl
x:Class="Windows8StoreTest.TestUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Width="70"
Height="40">
<StackPanel>
<Button Content="Hello" Foreground="Pink" BorderBrush="Pink"/>
</StackPanel>
</UserControl>
I've dropped the user control onto my page and give it a name:
<Page
x:Class="Windows8StoreTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:TestUserControl Name="testControl"/>
</Grid>
</Page>
However, when I go to the code behind I can't access the control by that name. It doesn't seem to exist! What is weird is that the control doesn't exists within InitializeComponent() method for the MainPage class which will be why it does exist.
What am I missing from my user control?
I'm using Windows 8 Store, XAML, c#.
Thanks in advance
Try to use this:
<local:TestUserControl x:Name="testControl"/>
Should work...
hello i don't know what is wrong but it should work.i have just made a sample example of it..i am putting it here hope you have done the same way.
<Page
x:Class="App12.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App12"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:MyUserControl1 x:Name="hellousercontrol" />
</Grid>
in my mainpage.cs.. i have just use it like this..
public MainPage()
{
this.InitializeComponent();
hellousercontrol.Height = 100;
}
one more this..have build your solution ?
I had the same issue in c++ environment. I observed, I didn't had default constructor in my class, as soon as I added the default constructor, I could use the defined UserControl in my project through XAML file. However without default constructor I was able to use it from within c++ code.

Can not maximize the child window in wpf

I am rewriting an old application built in FoxPro and my client doesnt want any change in GUI so I have to make an old DOS style GUI application using wpf, and here is where my problem starts.
The older application was a full screen application so here too I have to make it full screen no task bars..nothing. Now I changed the properties and everything was working very fine in my first window. but as soon as I use window2.showdialog() to invoke my second window, which too should go full screen BOOM...despite of the fact that I am using identical settings second window leaves some space at bottem (though it is border less and all) now I dont know whats going wrong here....
Here is my first window which works perfectly:
<Window x:Class="WpfAppMT.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:mt="clr-namespace:WpfAppMT"
Title="MT" WindowStyle="None" WindowState="Maximized" ResizeMode="CanResize" SizeToContent="WidthAndHeight" Topmost="False" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="640" d:DesignWidth="480">
<Viewbox Stretch="Fill">.....</Viewbox></Window>
here is the screens shot of the first window which is perfectly fine:
and this is the xaml of my second window, which when invoked from the first window's event handler is always cut short at bottom
<Window
x:Class="WpfAppMT.accountheads"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="accountheads" Background="#FF008284" WindowStyle="None" WindowState="Maximized" ResizeMode="CanResize" SizeToContent="WidthAndHeight" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="640" d:DesignWidth="480" KeyDown="Window_KeyDown">
.....</Window>
Here you can see that the second window is not full screen but leaves a lot of space at the bottom I dont understand the reason behind this peculiar behavior...
Apart from that I am facing a peculiar problem the GUI of application looks different on different OS's...I mean I am devolping it on an XP machine where it looks differently(the positions/length/widths), and today when I tested it on windows 7, there is lot of difference in look. You can see that in the second window text box which was supposed to be at the bottom has come up
OK..so after some trial and error I found the solution, In this case problem was with SizeToContent property I have set it to WidthandHeight but it should be set to Manual, so this answers the full screen question but still the prolem with portability persists

Categories

Resources