How to render Window custom Title using XAML? - wpf

I have a Windows Forms Application that shows application Name on most application Forms as shown below. For application name 'VScodePrint 2015' I used a bitmap. To support high resolution screens I had to make a number of copies of this image to support different DPI settings.
I have just started redesigning my application using WPF to avoid having to set different images based on the DPI setting without using images.
I have created a WPF window but not sure how to render the application name like the Windows Forms version above.
Can some please show me how to render the application as per Windows Form version using XAML?

System.IO.Path.GetFileName(Assembly.GetEntryAssembly().GetName().Name);
Set a label or whatever control's content equal to that, and you will get the name as you are wanting.

I have managed to create a usercontrol that renders Window title for my windows. I am novice using WPF so may this not be the best XAML but here it is:
<UserControl x:Class="WindowTitle"
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:WpfApplication2"
mc:Ignorable="d" Height="109.986" Width="404.929">
<RowDefinition Height="80"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border BorderBrush="DarkGray" BorderThickness="1" CornerRadius="10,10,0,0 " Background="#FF61238B" Margin="0,0,0,1">
<StackPanel Width="Auto" Height="Auto">
<StackPanel Height="Auto" Margin="0,0,0,0" HorizontalAlignment="Center" >
<Label x:Name="lblYear" Content="2015" FontSize="12" BorderBrush="White" Foreground="White" HorizontalContentAlignment="Right" Padding="0,0,0,0" VerticalAlignment="Bottom" FontFamily="Global User Interface" Margin="0,5,0,0"/>
<Label x:Name="lblProductName" Content="VScodePrint" FontSize="48" BorderBrush="White" Foreground="White" HorizontalContentAlignment="Right" Padding="0,0,0,0" VerticalAlignment="Top" FontFamily="Global User Interface" Margin="0,-5,0,0"/>
</StackPanel>
</StackPanel>
</Border>
<Label x:Name="lblVersion" Content="Version 14.0.20 Rev 1510" Grid.Row="1" VerticalAlignment="Center" Height="37" HorizontalContentAlignment="Center" Margin="0,0,0.429,0" FontFamily="Segoe UI Semibold">
<Label.Background>
<SolidColorBrush Color="#FFDBCBE3"/>
</Label.Background>
</Label>

Below is the above Window Title usercontrol in action:

Related

Control blocking input to lower control

Hopefully this is a WPF issue and not a esri issue. I have an ESRI map control, and I am placing a control on top of the map. When I do this, the map no longer receives input(I can't move around or click anything). If I modify the z-index of the top control to place it behind the map, the map works fine again.
<Grid Name="MapGrid" DockPanel.Dock="Top" >
<Grid Name="MapGrid" DockPanel.Dock="Top" >
<esri:MapView x:Name="MainMapView" Panel.ZIndex="0" KeyDown="MyMapView_KeyDown" MapViewTapped="MyMapView_MapViewTapped" Map="{Binding Source={StaticResource MapResource}}" WrapAround="True" Grid.Row="0" Grid.Column="0" Initialized="MyMapView_Initialized" >
</esri:MapView>
<Expander Header="Properties" ExpandDirection="Right" Panel.ZIndex="-1">
<ItemsControl Background="Transparent" Height="700" Width="500" HorizontalAlignment="Left" VerticalAlignment="Top" Name="FeaturePropertyRegion" cal:RegionManager.RegionName="FeaturePropertyRegion" />
</Expander>
</Grid>
This code works, but if I raise the ZIndex of the Expander pannel, the map no longer receives input. I am assuming the issue has to do with the visual tree of WPF, and how input cascades down. Any ideas on what the issue could be? Thanks.
EDIT
The issue seems to be with the expander, as the map works if I remove the expander and just have the ItemsControl.
Try :
<Expander IsHitTestVisible="False">
<ItemsControl />
</Expander>
It doesn't seem to be a problem with extender, which would be very wired if it did
I tried this :
<Grid>
<Button />
<Expander HorizontalAlignment="Left" ExpandDirection="Right" VerticalAlignment="Top">
<Rectangle Fill="Red" Stretch="Fill" Width="525" Height="350"/>
</Expander>
</Grid>

Is it possible to render Silverlight elements on top of a Web Browser control (in OOB mode)

I would like to be able to hide and reveal Web Browser controls using other Silverlight elements and various transitions.
It appears that any Web Browser controls are always rendered last on the page. Is there any way to get other elements to render on top of the Web Browser?
Here is a minimal XAML example to show the problem:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="BrowserSilverlightApplication.MainPage"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" Background="White">
<WebBrowser x:Name="webBrowser" Margin="16" Loaded="WebBrowser_Loaded"/>
<Rectangle Fill="#447171DE" Margin="8" Stroke="Black" IsHitTestVisible="False" StrokeThickness="0">
<Rectangle.Effect>
<BlurEffect Radius="18"/>
</Rectangle.Effect>
</Rectangle>
</Grid>
</UserControl>
With the release of Silverlight 4.0, the WebBrowser control was introduced. But, it was designed only to be used in an ‘Out Of Browser’ application. However, with the release of Silverlight 5, the control can also be used in an ‘In-browser” trusted application.
Since the introduction of the WebBrowser control in Silverlight, many developers have been using it to display HTML content inside the application. But, the major limitation is the “Airspace” issue.
In an application window each pixel within the windows belongs to exactly only one HWND, which constitutes the airspace for that HWND. The HWND can render only on those pixels which belongs to it.
In a typical Silverlight OOB application, there will be only one Silverlight-HWND. So, the entire pixels in the Silverlight application belong to this HWND and that constitutes the airspace for that.
But, in our scenario when we introduce a WebBrowser control in our Silverlight OOB application, the Airspace is shared by the HWND of the WebBrowser control. And that is known as Airspace issue.
The pixels on which the WebBrowser control resides will belong to the WebBrowser-HWND. So, Silverlight will not be able to render anything on the pixel which belongs to other HWND.
This problem is because; the WebBrowser control available in Silverlight is a wrapper around the “System.Windows.Controls.WebBrowser” control. The other Silverlight control will not create a new window for itself; rather it will be created under a single HWND. The WebBrowser control is not a real Silverlight control, but a wrapper around Windows HTML control. These native controls will create their own HWND.
Because of this, the WebBrowser control always overlaps other controls within the application. For example, when the page with the fixed header and scroll functionality are being used or when the WebBrowser control is placed under a menu control. There could be other instances.
By using the “WebBrowserBrush”, we can overcome this problem.
The WebBrowserBrush was introduced with the WebBrowser control, and they are designed to work together to display rich HTML content.
WebBrowserBrush is a type of Brush object which paints an area with HTML content. This HTML content is provided by a WebBrowser control. Just like the other brush types, you can use a WebBrowserBrush to fill a rectangle, geometry contents of path and much more.
So, how is this brush going to help us resolve this problem?
To overcome this problem, you can hide the WebBrowser and use a WebBrowserBrush to paint the area with HTML content from the WebBrowser. The WebBrowserBrush will paint the HTML content in the same layer as other control, and will allow other controls to be displayed above it. We can show the WebBrowser control when it is needed. The only thing which we need to consider is to find an appropriate event to handle this logic.
In the sample application below, I want my combobox list to render above the WebBrowser when open. I have used the ComboBox_DropDownChanged event to handle the logic. When the list is open, I hide the WebBrowser control and paint the area with the WebBrowserBrush. I then bring the control back when the list is closed.
> <UserControl x:Class="SilverlightApplication1_WebBrowser.MainPage"
> 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">
> <Grid x:Name="LayoutRoot" Background="White"
> HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
> <Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
> <Grid.RowDefinitions> <RowDefinition Height="50"
> /> <RowDefinition Height="50" />
> <RowDefinition Height="Auto" /> </Grid.RowDefinitions>
> <Grid.ColumnDefinitions> <ColumnDefinition
> Width="*"/> <ColumnDefinition Width="50"/>
> </Grid.ColumnDefinitions> <ComboBox
> Canvas.ZIndex="10" Grid.Row="0" x:Name="cbTestList"
> DropDownOpened="cbTestList_DropDownOpened"
> DropDownClosed="cbTestList_DropDownClosed" >
> <ComboBox.Items> <ComboBoxItem Content="--
> Select --" IsSelected="True"/> <ComboBoxItem
> Content="Text1"/> <ComboBoxItem
> Content="Text2"/> <ComboBoxItem
> Content="Text3"/> <ComboBoxItem
> Content="Text4"/> <ComboBoxItem
> Content="Text5"/> <ComboBoxItem
> Content="Text6"/> <ComboBoxItem
> Content="Text7"/> <ComboBoxItem
> Content="Text8"/> <ComboBoxItem
> Content="Text9"/> <ComboBoxItem
> Content="Text10"/> <ComboBoxItem
> Content="Text11"/> <ComboBoxItem
> Content="Text12"/> <ComboBoxItem
> Content="Text13"/> <ComboBoxItem
> Content="Text14"/> <ComboBoxItem
> Content="Text15"/> </ComboBox.Items>
> </ComboBox>
> <WebBrowser x:Name="wb" Height="500" Width="800" Grid.Column="0"
> Grid.ColumnSpan="2" Grid.Row="2"
> Canvas.ZIndex="0" HorizontalAlignment="Stretch"
> VerticalAlignment="Stretch" />
> <TextBox x:Name="txtUrl" Margin="10" Grid.Row="1" Grid.Column="0"
> Canvas.ZIndex="10"/> <Button Grid.Column="1"
> Grid.Row="1" Margin="10" Canvas.ZIndex="10" Content="Go"
> Name="btnLoadContent" Click="btnLoadContent_Click" />
> <Rectangle Grid.Column="0" Height="500" Width="800"
> Grid.ColumnSpan="2" Grid.Row="2"
> HorizontalAlignment="Stretch"
> VerticalAlignment="Stretch"> <Rectangle.Fill>
> <WebBrowserBrush SourceName="wb" x:Name="WBB1"/>
> </Rectangle.Fill> </Rectangle> </Grid>
> </Canvas> </Grid> </UserControl>
Though we are able to overcome the problem using a WebBrowserBrush along with the WebBrowser control, we still have a couple of limitations which we need to consider.
1.The user cannot interact with the WebBrowserBrush.
2.The changes in the WebBrowser control will not reflect automatically unless redrawn.
This is a simple workaround to the problem and it will work if designed properly, considering the limitation we have.

Layout navigation window

I would like to build a WPF window application using the following layout structure. Consider title and button on left hand frame/window like "Master Pages" in ASP.Net. On the right hand frame it should be a WPF navigation window.
When I include Navigation Window as an UI element at the last stack panel, it throws me and error. How should I design the entire layout according to the image screenshot below? Thanks
<Window x:Class="MainWindow"
xmlns:local="clr-namespace:ClientSocket"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title=" Desktop" Height="841" Width="1271" WindowStartupLocation="CenterScreen" WindowState="Maximized">
<DockPanel>
<StackPanel DockPanel.Dock ="Top" Orientation="Horizontal" Background="Red">
<TextBlock Background="red" FontSize ="36" Width="482" >
Main Title
</TextBlock>
</StackPanel>
<StackPanel Background="LightGray" DockPanel.Dock ="Left" Width="145">
<Button Content="Button1" Name="btnAndroid" Width="119" Margin="3" BorderBrush="{StaticResource {x:Static SystemColors.InfoBrushKey}}" />
<Button Content="Button2" Name="btnDownloads" Width="119" Margin="3" BorderBrush="{StaticResource {x:Static SystemColors.InfoBrushKey}}" />
<Button Content="AddNewDownloads" Height="37" Name="Button1" Width="133" />
</StackPanel>
<StackPanel>
<NavigationWindow Height="auto" Width="auto" Name="nwMain" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" BorderBrush="Blue" BorderThickness="1" />
</StackPanel>
</DockPanel>
</Window>
You cannot add a window as the child of anything, there is a nestable navigation control which you can use here instead, it is called Frame.
Layout-wise i would recommend a Grid with two rows, contains another Grid (in Grid.Row="1") with two columns.
DockPanels are sad controls that probably should not be used, unless someone points a gun at you and tells you to.

Silverlight and Unexpected Font Sizes

Someone please teach me to fish here...
I'm just learning Silverlight and have ran into a few situations where the font size actually used is drastically different than I would expect. There's probably something conceptual that I'm missing.
Case A
In one instance, I have defined a user control that presents a Label to show text. If one clicks on the label, the label (that is in a stack panel, in the user control) is replaced with a TextBox. When used at the top of a page (as in the example below with lblName) the label text is very small (around 8 points). When clicked on, the text box that replaces the label uses the specified fonts size. That same user control, used in different parts of the app, uses the same font for Label and TextBox.
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="33" />
<RowDefinition Height="267*" />
</Grid.RowDefinitions>
<StackPanel Height="Auto" HorizontalAlignment="Left" Name="stackPanel" VerticalAlignment="Top" Width="Auto" Grid.Row="1" />
<my:EditLabel Height="33" HorizontalAlignment="Left" x:Name="lblName" VerticalAlignment="Top" Width="Auto" FlexText="{Binding Name, Mode=TwoWay}" FontSize="20" MinHeight="24" />
</Grid>
Case B
I'm using the LiquidMenu.Menu control to pop up a menu when a button is pressed. The font looks huge compared to the rest of my page (maybe 36 points?). I tried forcing it to a very small by explicitly setting it to 8pt, but that had no effect.
<Grid x:Name="LayoutRoot" Background="{x:Null}">
<StackPanel x:Name="labelStackPanel" Orientation="Horizontal">
<TextBlock Height="24" HorizontalAlignment="Left" Name="labelText" VerticalAlignment="Top" Width="200" Text="(Value Goes Here)" />
</StackPanel>
<liquidMenu:Menu x:Name="popupMenu" Canvas.Left="40" Canvas.Top="40" ItemSelected="MenuList_ItemSelected" Visibility="Collapsed" Height="Auto" FontSize="8">
<liquidMenu:MenuItem ID="delete" Icon="Images/Delete10.png" Text="Delete" Shortcut="Del" />
<liquidMenu:MenuItem ID="exclusive" Icon="" Text="Exclusive" Shortcut="Ctrl+E" />
<liquidMenu:MenuItem ID="properties" Icon="" Text="Properties" Shortcut="Ctrl+P" />
</liquidMenu:Menu>
</Grid>
Answers to these specific issues are great, a new way to think about this type of issue so that I understand how to control font size is better.

WPF TabIndex in a composite control

I have a simple window with a simple composite control embedded within it.
(Main Window)
<Window x:Class="TabOrder.Window1"
xmlns:local="clr-namespace:TabOrder"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Label HorizontalAlignment="Left" VerticalAlignment="Top">First</Label>
<TextBox TabIndex="0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="80,0,0,0"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,30,0,0">Second</Label>
<TextBox TabIndex="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="80,30,0,0"/>
<local:MyControl Margin="0,60,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch" TabIndex="2"/>
</Grid>
(Composite control)
<UserControl x:Class="TabOrder.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Label HorizontalAlignment="Left" VerticalAlignment="Top">Third</Label>
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="80,0,0,0"/>
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,30,0,0">Fourth</Label>
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="80,30,0,0"/>
</Grid>
As expected on my form I get 4 text boxes...
First
Second
Third
Fourth
But when "First" has focus and I hit tab the focus is switched to "Third". WPF seems to be seeing the tab list as a single flat list rather than as a tree where MyControl is TabIndex 3 and the text box "Third" the first tabbed control within it.
Is this a bug in WPF or is there another way of doing this? The composite control is used in many windows, it could even be used more than once on a single window.
I know this response is quite late... but have you tried:
<UserControl ... KeyboardNavigation.TabNavigation="Local">
Doing so will ensure once your UserControl has recieved focus, you will navigate only through TabStop within your UserControl (instead of worring about conflicting TabIndex values throughout your app). After looping through the TabStops of your UserControl, TabNavigation will resume to the TabStop outside of it.
http://msdn.microsoft.com/en-us/library/system.windows.input.keyboardnavigationmode.aspx

Resources