I'm trying to set the ZoomOrigin of the Zoombox in the xaml, but if I set a coordinate, it will not zoom anywhere.
<Window x:Class="WpfApp1.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:WpfApp1"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<xctk:Zoombox x:Name="zoom" ZoomOrigin="20,20">
<Image Source="Green.png" Height="200" Width="200"/>
</xctk:Zoombox>
</Grid>
</Window>
I just want the origin of the zoom to be a set of coordinates decided by me, not by default.
Without setting ZoomOrigin it zooms in the middle of the zoom box - where I put the mouse cursor doesn't matter since the zoom will only occur in the middle of the box.
Trying to set the ZoomOrigin to a value breaks everything and it stops zooming.
Related
Recently I want to make a custom window with WPF for my program.
Here is the code of the Window:
<Window x:Class="Test.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:Test"
mc:Ignorable="d"
Title="Test" Height="450" Width="850" Background="Transparent" AllowsTransparency="True" WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip" WindowStyle="None">
</Window>
I want to recreate a titlebar that I set the WindowStyle to None.
Now I need to resize the window with the grip. However, the Grip will not work anymore if I set the WindowStyle to None.
In spite I can set the ResizeMode to CanResizeWithGrip. Whereas, it only works on the bottom right side of the Window.
I want to make the Grip work all sides of the window. How can I achieve it?
You can set the ResizeBorderThickness property of a WindowChrome to make a custom window resizable:
<Window x:Class="WpfApp1.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"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" WindowStyle="None">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0" ResizeBorderThickness="5" />
</WindowChrome.WindowChrome>
<Grid Background="Yellow">
<TextBlock>Resizable window...</TextBlock>
</Grid>
</Window>
I have a wfp which need:
remove the non-client frame from the window
be not included when recording screen
set window background transparent
When I set window with WindowStyle.None, it fails when calling SetWindowDisplayAffinity to exclude it from being recorded. So I customize the window with WindowChrome. It works well, but the window background is black when I set it transparent.
<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Background="Transparent"
Title="MainWindow" Height="50" Width="400">
<WindowChrome.WindowChrome>
<WindowChrome x:Name="Chrome"
GlassFrameThickness="0"
ResizeBorderThickness="0"
CaptionHeight="0"/> </WindowChrome.WindowChrome>
</Window>
Anything wrong? Or are there other ways to realize such requirements?
I'm creating a wpf application and the main page consist of a sidebar a header and a content area where the rest of the app will be displayed, since i come for an angular background can i split the sidebar and the header and the content area into small maintainable components and how can it be achieved
In your Solution Explorer, right click on your project and add a new UserControl. Call it for example "FeatureView". In that UserControl, insert a textblock with a dummy text like:
<UserControl x:Class="WpfApp10.FeatureView"
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:WpfApp10"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBlock Text="This is my FeatureView UserControl"/>
</Grid>
Then, in your MainWindow load it in the following way:
<Window x:Class="WpfApp10.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:WpfApp10"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<local:FeatureView/>
</Grid>
You should be able to see your dummy text. You can expand this with more UserControls.
You can split the areas into user controls:
https://learn.microsoft.com/en-us/visualstudio/extensibility/adding-user-control-to-the-start-page?view=vs-2017
A nice way of managing this is to use Prism Regions, see:
https://rohiton.wordpress.com/2016/06/08/understanding-prism-part-2-regions/
I create a window in wpf and in xml file I write this code:
<Window x:Class="WPFTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid >
</Grid>
</Window>
But when I run the project, the size of window is 1080*625. I expect the window size become the screen size, but isn't. Why?
You need to set WindowState to Maximmized:
<Window x:Class="WPFTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" WindowState="Maximized"/>
I'm trying to hide a control during a window resize because it's not behaving right otherwise. However in WPF there doesn't seem to be any OnBeginResize-ish event.
Any suggestions how to achieve this in WPF?
Bind a property(Notifiable) to your window width so when the width changes Setter of this property will be invoked and within this setter you can have the logic to hide your control.
<Window x:Class="SiemensEnergy.Frw.Main.Client.UI.Views.MainWindowView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewmodel="clr-namespace:SiemensEnergy.Frw.Main.Client.UI.ViewModels"
Title="MainWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Width="{Binding WindowWidthProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
</Window>
Window_SizeChanged?
<Window x:Class="TestControls.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:WFControls;assembly=WFControls"
xmlns:ff="clr-namespace:WFControls.Fernfracht;assembly=WFControls"
Title="MainWindow" Height="350" Width="525" SizeChanged="Window_SizeChanged">
<DockPanel>
</DockPanel>
</Window>