Is it possible to set UserControl always topmost over the app? - c#

I'm making FeedBack option in my WPF app. The main window has TabControl and statusbar below. Statusbar has a button, which shows FeedBackView with animation.
So, FeedBackView is not a window, it's a UserControl, which contains in Canvas Border.
The app has some options, which open other modal windows, so in that moment FeedBack form is inaccesible. I've tried to set Panel.ZIndex = 1 and that didn't help. So is there any way to set the form super topmost within the app?
<UserControl x:Class="UPR.Wpf.App.Views.StatusBarContentView"
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:v="clr-namespace:UPR.Wpf.App.Views.FeedBack"
xmlns:vm="clr-namespace:UPR.Wpf.App"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Loaded="UserControl_Loaded">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Styles/Buttons.xaml"/>
</ResourceDictionary.MergedDictionaries>
<BooleanToVisibilityConverter x:Key="xBooleanToVisibilityConverter"/>
</ResourceDictionary>
</UserControl.Resources>
<Canvas>
<Button Name="FeedBackButton"
Click="FeedBackButton_Click"
Loaded="FeedBackButton_Loaded"
BorderThickness="0.5"
BorderBrush="Gray"
Foreground="White"
FontWeight="Bold"
FontSize="15"
Height="32"
Canvas.Bottom="-17"
Canvas.Right="-150">
</Button>
<Border BorderBrush="Gray"
Panel.ZIndex="1"
BorderThickness="2"
Name="border"
Margin="-350,0,-178,-9"
Background="White"
Canvas.Bottom="24"
Canvas.Right="-5"
SizeChanged="border_SizeChanged">
<v:FeedBackView/>
</Border>
</Canvas>
</UserControl>

Related

How to load user components in a panel on click of buttons?

I have two panels which are added to a user control (SalesLandingPage).
In column2, i have a user control SaleOrderCommandOptions which has a stack panel with 2 buttons (order & checkout)
On order click, I need to show orderUserControl in column1 of SalesLandingPage ...
and similarly on clicking checkout, I need to show checkoutUserControl in column1 of SalesLandingPage.
Can anyone guide me on how to achieve the same?
Below is the code -
MainWindow.xaml
<telerik:RadTabbedWindow x:Class="WPFInterplayPOS.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:userControls="clr-namespace:WPFInterplayPOS.UserInterface.Sales"
xmlns:local="clr-namespace:WPFInterplayPOS" WindowState="Maximized" Height="513.424" Width="844.321"
AddButtonVisibility="Hidden" HideMinimizeButton="True" HideMaximizeButton="True" ResizeMode="NoResize">
<telerik:RadTabItem Header="Sales" CloseButtonVisibility="Hidden" HorizontalContentAlignment="Right">
<userControls:SalesLandingPage></userControls:SalesLandingPage>
</telerik:RadTabItem>
</telerik:RadTabbedWindow>
SalesLandingPage.xaml
<UserControl x:Class="WPFInterplayPOS.UserInterface.Sales.SalesLandingPage"
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:WPFInterplayPOS.UserInterface.Sales"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
xmlns:telerikPresentation="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<!-- Grid layout column definitions -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="8*"></ColumnDefinition>
<ColumnDefinition Width="3*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!-- RadNavigationView in column 0 -->
<telerik:RadNavigationView x:Name="navigationView" Grid.Column="0" DisplayMode="Compact" AutoChangeDisplayMode="False" PaneToggleButtonVisibility="Hidden">
<telerik:RadNavigationView.Items>
<telerik:RadNavigationViewItem>
<telerik:RadNavigationViewItem.Icon>
<telerikPresentation:RadGlyph Glyph="" FontSize="16"/>
</telerik:RadNavigationViewItem.Icon>
</telerik:RadNavigationViewItem>
<telerik:RadNavigationViewItem>
<telerik:RadNavigationViewItem.Icon>
<telerikPresentation:RadGlyph Glyph="" FontSize="16"/>
</telerik:RadNavigationViewItem.Icon>
</telerik:RadNavigationViewItem>
<telerik:RadNavigationViewItem>
<telerik:RadNavigationViewItem.Icon>
<telerikPresentation:RadGlyph Glyph="" FontSize="16"/>
</telerik:RadNavigationViewItem.Icon>
</telerik:RadNavigationViewItem>
</telerik:RadNavigationView.Items>
<telerik:RadNavigationView.Content>
<TextBlock Text="Content" Foreground="Black" Margin="5"/>
</telerik:RadNavigationView.Content>
</telerik:RadNavigationView>
<!-- column 1 -->
<StackPanel x:Name="SaleOrderCommandView" Grid.Column="1">
<!-- Display relevant user control here based on button click in SaleOrderCommandOptions user control -->
</StackPanel>
<!-- SaleOrderCommandOptions in column 2 -->
<local:SaleOrderCommandOptions Grid.Column="2">
</local:SaleOrderCommandOptions>
</Grid>
</UserControl>
SaleOrderCommandOptions.xaml
<UserControl x:Class="WPFInterplayPOS.UserInterface.Sales.SaleOrderCommandOptions"
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:telerikPresentation="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:local="clr-namespace:WPFInterplayPOS.UserInterface.Sales"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Telerik.Windows.Controls;component/Themes/FontResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel Grid.Column="2" Background="{telerikPresentation:MaterialResource ResourceKey=PrimaryHoverBrush}">
<telerik:RadButton>Order</telerik:RadButton>
<telerik:RadButton>Checkout</telerik:RadButton>
</StackPanel>
</UserControl>

WPF page content not setting to window's size

I made a WPF application in which. I placed a rectangle. The page is covering whole window but the size(width) of rectangle is not equal to the page.
here is the pic.
here is the source code of my application:
<Page x:Class="TestWpfApplication.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"
xmlns:local="clr-namespace:TestWpfApplication"
mc:Ignorable="d"
d:DesignHeight="350" d:DesignWidth="525"
Title="Page1" Background="#FF7ACBBC" ShowsNavigationUI="False">
<Grid>
<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Stroke="Black" VerticalAlignment="Top" Width="525"/>
<Label x:Name="label" Content="Heading" HorizontalAlignment="Left" Margin="222.006,25,0,0" VerticalAlignment="Top" FontFamily="Tahoma" FontSize="22"/>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="160,155,0,0" TextWrapping="Wrap" Text="And rest of the content goes here" VerticalAlignment="Top" FontFamily="Tahoma" FontSize="14"/>
</Grid>
And
<Window x:Class="TestWpfApplication.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:TestWpfApplication"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<local:Page1/>
</Grid>
At last App.xaml
<Application x:Class="TestWpfApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestWpfApplication"
StartupUri="page1.xaml">
<Application.Resources>
</Application.Resources>
Please help me....
Set SizeToContent Property of Window to SizeToContent="WidthAndHeight"
SizeToContent
Page1.Xaml.cs:
public Page1()
{
InitializeComponent();
this.SizeToContent = SizeToContent.WidthAndHeight;
}
For more Info, See Window.SizeToContent Property
I don't know why you specified size parameters for rectangle and expect it to fit your page's size. Just remove all these parameters and it will stretch.
<Rectangle Fill="#FFF4F4F5"/>

WPF - XAML Page Center to Window

I'm building a WPF app using .NET 4.0 and MVVM Light.
I have implemented navigation in the app using a single Window with a Frame that is changing based in my current view.
Here's the code I have in my MainWindow.xaml:
<Controls:MetroWindow x:Class="App.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:resx="clr-namespace:App.Resources"
xmlns:utils="clr-namespace:App.Utils"
Title="{Binding Path=Content.Title, ElementName=MainFrame}"
Height="{Binding Source={x:Static SystemParameters.PrimaryScreenHeight}, Converter={utils:RatioConverter}, ConverterParameter='0.9' }"
Width="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}, Converter={utils:RatioConverter}, ConverterParameter='0.9' }"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Frame Source="\Views\LoginView.xaml" NavigationUIVisibility="Hidden" Name="MainFrame"></Frame>
</Grid>
</Controls:MetroWindow>
By default, the MainWindow is occupying the 90% of the screen. I would like to center the contents of the MainFrame inside the MainWindow.
Is it posible? How can I do it? I guess it's a simple task to do, but I've been looking for 1 hour and I couldn't find something specific.
Since you are using a grid, you can insert a stackpanel and center them out, like this:
<Grid VerticalAlignment="Center">
<StackPanel HorizontalAlignment="Center">
<Frame Source="\Views\LoginView.xaml" NavigationUIVisibility="Hidden" Name="MainFrame"></Frame>
</StackPanel>
</Grid>

WPF Extended Toolkit Control in Custom Control not pulling through to form?

I am using the Xceed Extended WPF Toolkit for the Integer Up Down Control. I have installed this via Nuget.
I have the integrated into a custom control which contains other normal textboxes and button etc.
This custom control I then put in a tab control on a Window. Everything shows correctly apart from this IntegerUpDown which shows as an empty box. (It is fine when looking at the custom control in design)
I have added the namespace to both the control and window so am not sure what the problem is. Everything is inside one project so I don't think references are a problem.
Any ideas of what I could be missing?
Control XAML:
<Label Grid.Row="3" Content="Quantity of Tickets:" VerticalAlignment="Center"></Label>
<xctk:IntegerUpDown Grid.Row="3" Grid.Column="1" Name="numTickets"></xctk:IntegerUpDown>
Form XAML:
<TabItem Header="New Booking">
<Grid Background="#FFE5E5E5">
<btc:NewBooking></btc:NewBooking>
</Grid>
</TabItem>
Thanks,
Ryan
Here's a MCVE:
MainWindow:
<Window
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:WpfApplication8"
x:Class="WpfApplication8.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="300">
<Grid>
<TabControl x:Name="tabControl" Margin="0">
<TabItem Header="TabItem 1">
<Grid Background="#FFE5E5E5">
<local:UserControl1></local:UserControl1>
</Grid>
</TabItem>
<TabItem Header="TabItem 2">
<Grid Background="#FFE5E5E5"/>
</TabItem>
</TabControl>
</Grid>
UserControl:
<UserControl x:Class="WpfApplication8.UserControl1"
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:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:WpfApplication8"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<StackPanel>
<Label Grid.Row="3" Content="Quantity of Tickets:" VerticalAlignment="Center"></Label>
<xctk:IntegerUpDown Grid.Row="3" Grid.Column="1" Name="numTickets"></xctk:IntegerUpDown>
</StackPanel>
</Grid>
Both MainWindow and UserControl are at the same level in the project structure:
EDIT: One more thing, make sure your UserControl is fully contained by the MainWindow and you do NOT have something like this:
That would cause the IntegerUpDown look like an empty box, like you described.

How to set a resize limit for a window?

Lets say I have a xaml for my window like this:
<Window x:Class="WavePoint_MVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FontSize="13"
FontFamily="Verdana"
xmlns:local="clr-namespace:WavePoint_MVVM"
Height="{Binding SystemParameters.PrimaryScreenHeigth}"
Width="{Binding SystemParameters.PrimaryScreenWidth}"
AllowsTransparency="False"
WindowStartupLocation="CenterScreen"
ResizeMode="CanResizeWithGrip"
<Grid/>
</Window>
Now I want to fix some sort of limit in which the user can't resize the window beyond it. Just to give an example, in Spotify app for Windows desktop, the user can't resize beyond a certain limit. This is the minimum I can get:
Thoughts?
To force a minimum window size, set your MinWidth and MinHeight attributes on the Window:
<Window x:Class="WavePoint_MVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FontSize="13"
FontFamily="Verdana"
xmlns:local="clr-namespace:WavePoint_MVVM"
Height="{Binding SystemParameters.PrimaryScreenHeigth}"
Width="{Binding SystemParameters.PrimaryScreenWidth}"
AllowsTransparency="False"
WindowStartupLocation="CenterScreen"
ResizeMode="CanResizeWithGrip"
MinWidth="640"
MinHeight="480">
<Grid/>
</Window>

Categories

Resources