how to set header for change place of app window - c#

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.

Related

Edit Xaml files on debuging Visual studio 2019, WPF

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/

WPF Can't find local resource when executed

I'm defining an application resource in my app that stores my ViewModels with a navigation element to navigate pages. This is working fine in the xaml editor of visual studio since all the data bindings are working there. However when I try to run the application in debugger it trows an Exception with the message Cannot find source with the name ViewModelLocator. Does anyone know what is going wrong?
I have a local resource defined in my App.xaml like this:
<Application.Resources>
<viewmodel:ViewModelLocator x:Key="ViewModelLocator"/>
</Application.Resources>
Which i try to use like this:
<Page x:Class="QardPrint.PageEmployeesList"
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:QardPrint"
xmlns:viewmodel="clr-namespace:QardPrint.ViewModel"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="PageEmployeesList"
DataContext="{Binding EmployeesListViewModel, Source={StaticResource ViewModelLocator}}">
My ViewModelLocator class looks like this
public class ViewModelLocator
{
public EmployeesListViewModel EmployeesListViewModel => new EmployeesListViewModel(App.Navigation);
}
Try to use ResourceDictionary:
App.xaml:
<Application xmlns:viewmodel="clr-namespace:QardPrint.ViewModel">
<Application.Resources>
<ResourceDictionary>
<viewmodel:ViewModelLocator x:Key="Locator" />
QardPrint.PageEmployeesLis.Xaml:
<Page x:Class="QardPrint.PageEmployeesList"
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:QardPrint"
xmlns:viewmodel="clr-namespace:QardPrint.ViewModel"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="PageEmployeesList"
DataContext="{Binding EmployeesListViewModel, Source={StaticResource Locator}}">
I Found the problem. It was in the App.xaml I deleted the startup parameter. After adding it again the problem was solved.
I did this because I made another window in the startup function of app.cs. But this is probably bad design anyway so going to figure out how to do it better.

Navigating between pages in wpf not working

I've done the simplest thing. I open a new window and put a frame in it and I wanted to show in the frame a page.
The window code:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
Page1 p = new Page1();
navigator.NavigationService.Navigate(p);
}
}
navigator is the frame, in Page1 I have black background color to see the difference. When I run it I still see the window and not the page that should be inside the frame. Why isn't this working?
Window:
Page:
But i get the white one.
The code for page 1:
<Page x:Class="test.Page1"
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="269" d:DesignWidth="292"
Title="Page1">
<Grid Background="Black">
</Grid>
In the cs side i didn't write anything.
You need to set the Content property of the Page to something to be able to actually see it:
<Page x:Class="test.Page1"
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="269" d:DesignWidth="292"
Title="Page1">
<Grid Background="Black">
<TextBlock>PAGE1</TextBlock>
</Grid>
</Page>
An empty black Grid is not visible but if you put a TextBlock in it you should be able to see it.

WPF Page Title Bar Hide

I know how to hide the title bar in windows: WindowStyle="none". But how can i achieve that with Pages?
I have a code like this:
<Page x:Class="SomeNamePage1"
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="SomeName"
mc:Ignorable="d"
d:DesignHeight="700" d:DesignWidth="700" WindowHeight="700" WindowWidth="700"
Title="Page1" Background="#FFFFFF">
How can i hide the title bar with the same results as WindowStyle="None"?
I figured out that's not possible. I solved using a Window as holder for the navigation menu and a frame that switches between Pages for the content.
Hope this helps others!

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

Categories

Resources