I'm using WindowChrome, and customising the border and the title bar of my application, and it works fine for the most part:
However, for some reason when I run on a certain Virtual Machine (in this case, a German language one using VMware), a white border and title bar (though with no title) appears, and covers my custom title bar:
The odd thing is that I have tried inspecting the application using Snoop, and even on the VM, Snoop does not seem to acknowledge this bar exists. e.g. hovering over the different WPF components, and if I use Snoop's "magnify" function, the title bar appears correctly!
Where could this title bar be coming from and how to get rid of it?
Here is XAML code for a simple application that exhibits the same problem:
<Window x:Class="XamlMessing.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:XamlMessing"
mc:Ignorable="d"
Title="MainWindow" Height="298" Width="399" Background="#FF590B0B">
<Window.Resources>
<WindowChrome x:Key="MyWindowChrome">
<WindowChrome.CaptionHeight>48</WindowChrome.CaptionHeight>
</WindowChrome>
<Style x:Key="MyWindowStyle" TargetType="{x:Type Window}" BasedOn="{StaticResource {x:Type Window}}">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="ResizeMode" Value="NoResize" />
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
<Setter Property="WindowState" Value="Normal" />
<Setter Property="WindowStyle" Value="SingleBorderWindow" />
<Setter Property="WindowChrome.WindowChrome" Value="{StaticResource MyWindowChrome}"/>
</Style>
</Window.Resources>
<Window.Style>
<StaticResource ResourceKey="MyWindowStyle"/>
</Window.Style>
<Grid Margin="0,0,81,107">
<TextBlock HorizontalAlignment="Left" Margin="125,89,0,0" TextWrapping="Wrap" Text="Hello, World" VerticalAlignment="Top" Height="61" Width="175" FontSize="24" Foreground="#FFDAE463"/>
</Grid>
</Window>
OK it seems to be fixed by setting...
<WindowChrome.GlassFrameThickness>0</WindowChrome.GlassFrameThickness>
But I would still be interested to know what was causing it to appear in the first place, since that setting wasn't required on devices other than the VM...
Related
I am writing a WPF (.net 5) application which should support accessibility specifically windows narrator to read out the screen text. I am using few TextBlocks and expect that as soon as window is shown narrator will start reading all the text present in the screen one by one.
What I observe is that while the Button's content are read out, any TextBlock content is not read by narrator at all.
How can I make the narrator to read all the content of the window one by one.
<Window x:Class="SampleApp.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:SampleApp"
mc:Ignorable="d"
TabIndex="0"
Focusable="True"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock x:Name="firstText"
Text="This is the first line"
KeyboardNavigation.TabIndex="1"
KeyboardNavigation.TabNavigation="Continue"
AutomationProperties.AutomationId="firstTextBox"
AutomationProperties.Name="This is the first line"
/>
<TextBlock x:Name="secondText"
Text="This is the second line"
KeyboardNavigation.TabIndex="2"
KeyboardNavigation.TabNavigation="Continue"
AutomationProperties.AutomationId="secondTextBox"
AutomationProperties.Name="This is the second line"
/>
</StackPanel>
</Grid>
</Window>
Here is a style I use that makes each textblock focusable when the Narrator is on, but does not create a bunch of extra tabs stops if Narrator is off.
<!-- WCAG variant -->
<Style x:Key="WCAG_TextboxStyle" TargetType="{x:Type TextBlock}"
BasedOn="{StaticResource {x:Type TextBlock}}" >
<Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
<Setter Property="Focusable" Value="False"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsNarratorOn}" Value="true">
<Setter Property="KeyboardNavigation.IsTabStop" Value="True"/>
<Setter Property="Focusable" Value="True"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="ToolBarButton" TargetType="{x:Type Button}">
<Setter Property="Control.Background" Value="#00000000"/>
<Setter Property="Control.Width" Value="25"/>
<Setter Property="Control.Height" Value="25"/>
</Style>
...
<Grid HorizontalAlignment="Left">
<Button Style="{StaticResource ToolBarButton}"/>
<Button Style="{StaticResource ToolBarButton}"/>
<Button Style="{StaticResource ToolBarButton}"/>
<Button Style="{StaticResource ToolBarButton}"/>
<Button Style="{StaticResource ToolBarButton}"/>
<Button Style="{StaticResource ToolBarButton}"/>
</Grid>
I wanna optimize my XAML code. I don't wanna assign a style to each button, but I wish every button to have my style.
Is it possible to do something like this? Only working ... :)
<Grid x:Name="gToolBar" Grid.Row="1" HorizontalAlignment="Left" Style="{StaticResource ToolBarButton}">
<Button/>
<Button/>
<Button/>
<Button/>
<Button/>
<Button/>
</Grid>
I don't use TargetType only, because I have other buttons with different styles.
I think it available, but i don't know how.
Thanks...
As i already said everything that is to be done in the comment, but for further clarification:
I wanna optimize my XAML code. I don't wanna assign a style to each button, but I wish every button to have my style.
Move the Style part to <Application.Resources> in App.xaml file, Like shown below:
<Application.Resources>
<Style TargetType="Button" >
<Setter Property="Control.Background" Value="#00000000"/>
<Setter Property="Control.Width" Value="25"/>
<Setter Property="Control.Height" Value="25"/>
</Style>
</Application.Resources>
Note: I've removed the x:Key part. Now this will apply to all the button's that is in the application.
I don't use TargetType only, because I have other buttons with different styles. I think it available, but i don't know how.
For this you would have to make a custom button as a UserControl, thus making them completely different from a usual Button. Apply styling to them in their own UserControl.Resources. Thus styling mentioned in App.Resources won't affect these custom made UserControls
You can create a default style for buttons within the grid:
<Window ...>
<Window.Resources>
<Style x:Key="ToolBarButton" TargetType="{x:Type Button}">
<Setter Property="Control.Background" Value="#00000000"/>
<Setter Property="Control.Width" Value="25"/>
<Setter Property="Control.Height" Value="25"/>
</Style>
</Window.Resources>
<Grid HorizontalAlignment="Left">
<Grid.Resources>
<Style x:Key="{x:Type Button}" BasedOn="{StaticResource ToolBarButton}" TargetType="{x:Type Button}"></Style>
</Grid.Resources>
<Button />
<Button />
<Button />
<Button />
<Button />
<Button />
</Grid>
</Window>
If you create a resource that uses a control type as key within a container, the style will get applied to all controls of the type within the container. If you want to define the original style somewhere else (for example because you use it in many place) you can base the local style off the global style.
You should use application resources to do that. add this code to there(app.xaml):
<Application.Resources>
<Style TargetType="Button" >
<Setter Property="Control.Background" Value="#00000000"/>
<Setter Property="Control.Width" Value="25"/>
<Setter Property="Control.Height" Value="25"/>
</Style>
</Application.Resources>
UPDATE
Or if you want this style apply just some part of your application such some special 'Grid' or special Window ..., just put it inside Resource of that element like this:
<Grid>
<Grid.Resources>
<Style TargetType="Button" >
<Setter Property="Control.Background" Value="#00000000"/>
<Setter Property="Control.Width" Value="25"/>
<Setter Property="Control.Height" Value="25"/>
</Style>
</Grid.Resources>
... inside code, and your buttons which we eant to apply style for them.
</Grid>
I'm using ComponentOne C1DataGrid control for Silverlight. Standard StyleInheritance does not work.
Here is the code:
<UserControl x:Class="TestSLStyles.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"
xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:sys="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<Style x:Key="BaseStyle" TargetType="Button">
<Setter Property="Background" Value="Yellow" />
</Style>
<Style x:Key="InheritedStyle" TargetType="Button" BasedOn="{StaticResource BaseStyle}">
<Setter Property="Foreground" Value="Red" />
</Style>
<Style x:Key="dchpBase" x:Name="dchpBase" TargetType="c1:DataGridColumnHeaderPresenter">
<Setter Property="Background" Value="Yellow"/>
</Style>
<Style x:Key="dchpInherited" x:Name="dchpInherited" TargetType="c1:DataGridColumnHeaderPresenter" BasedOn="{StaticResource dchpBase}">
<Setter Property="Foreground" Value="Red"/>
</Style>
</UserControl.Resources>
<StackPanel>
<Button Content="HelloWorld" x:Name="btn1" />
<Button Content="HelloWorld" x:Name="btn2" Style="{StaticResource BaseStyle}" />
<Button Content="HelloWorld" x:Name="btn3" Style="{StaticResource InheritedStyle}" />
<c1:C1DataGrid x:Name="grd1">
<c1:C1DataGrid.Columns>
<c1:DataGridTextColumn Header="Column1" x:Name="cln1" />
<c1:DataGridTextColumn Header="Column2" x:Name="cln2" HeaderStyle="{StaticResource dchpBase}" />
<c1:DataGridTextColumn Header="Column3" x:Name="cln3" HeaderStyle="{StaticResource dchpInherited}" />
</c1:C1DataGrid.Columns>
</c1:C1DataGrid>
</StackPanel>
</UserControl>
As you can see on screen below, this code works fine for Button's style inheritance, but not for grid's column header:
The last column supposed to be with Yellow background and Red foreground, but base style is not inherited. Tested on Silverlight 5 and ComponentOne version 4.0.20103.86
Question was posted to ComponentOne's forum as well
The issue was fixed with the C1Silverlight Build : 5.0.20133.381
The latest build can be downloaded from the following link :http://prerelease.componentone.com/hotfixes/silverlight/C1Silverlight_5.0.20141.399_RC1.msi
I have put my shared styles in a single resource dictionary which I include in the application. For example, in a file called GlobalStyles.xaml I have the following:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="BaseStyle" TargetType="FrameworkElement">...</Style>
<Style x:Key="ExtendedStyle" TargetType="FrameworkElement" BasedOn="{StaticResource BaseStyle}">...</Style>
</ResourceDictionary>
I include this file in the app.xaml as follows:
<Application.Resources>
<ResourceDictionary Source="GlobalStyles.xaml" />
</Application.Resources>
This should work but I am getting the following build error for the ExtendedStyle: Error: Index was outside the bounds of the array.. If I remove the BasedOn directive I get the same error for BaseStyle but none for ExtendedStyle. This is really wierd. Can anybody explain this error?
EDIT:
The styles are:
<Style x:Key="BaseStyle" TargetType="FrameworkElement">
<!-- Background -->
<Setter Property="Control.Background" Value="{StaticResource White0ColorBrush}"/>
<!-- Border -->
<Setter Property="Control.BorderBrush" Value="{StaticResource Green1ColorBrush}"/>
<Setter Property="Control.BorderThickness" Value="0"/>
<!-- Font -->
<Setter Property="Control.FontWeight" Value="Light"/>
<Setter Property="Control.Foreground" Value="{StaticResource Green0ColorBrush}"/>
</Style>
and
<Style x:Key="ExtendedStyle" TargetType="FrameworkElement" BasedOn="{StaticResource BaseStyle}">
<Setter Property="Control.Background" Value="{StaticResource Green1ColorBrush}"/>
<Setter Property="Control.Foreground" Value="{StaticResource White0ColorBrush}"/>
</Style>
I don't think there is anything special about these two styles. On restarting VS, I am getting the error for another style dependent on ExtendedStyle.
EDIT 2:
I created a new empty WPF Application project and included the GlobalStyles.xaml file in the app.xml. That built fine. Then I added just these lines to the window.xaml and got the same error:
<Grid>
<Border BorderThickness="2" CornerRadius="5" BorderBrush="{StaticResource White0ColorBrush}" Style="{StaticResource ExtendedBaseStyle}">
<Grid>
<TextBox x:Name="SearchField" Height="20" BorderThickness="0" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" />
</Grid>
</Border>
</Grid>
It has to be a bug with VS2012 which I am using. I moved to VS2010 and the problem went away. I have had numerous problems with VS2012 designer. It hangs frequently, throws exceptions, complains about syntax errors when there are none and now this. I will stick to VS2010 for now.
Hey, I have a WPF application targeted at XP machines. The problem is that we wish to run with a WPF XP luna theme rather than classic and most of our clients run in classic mode. Our clients are all internal, it's just that their machines were configured with XP classic.
In theory, this is as simple as adding this to the application:
<ResourceDictionary Source="/PresentationFramework.Luna, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35,
ProcessorArchitecture=MSIL;component/themes/luna.normalcolor.xaml" />
In practice, as soon as a touch any of the styles (say add a margin to TextBox), they styles seem to revert back to classic theme.
This displays correctly (Style Luna):
<TextBox Width="80" Height="20" />
This displays correctly (Style Luna):
<TextBox Width="80" Height="20" Background="Brown">
This displays incorrectly (Style Classic), note it does not matter now many nodes there are in the style block - zero is enough to confuse things:
<TextBox.Style><Style></Style></TextBox.Style></TextBox>
Long and short, overriding the default OS theme seems to preclude further use of styles. What am I missing here?
See the select answer for 80% of the story. The full story is this: I must supply the ‘BasedOn’ setting as well. Unfortunately, this means we can not override, say textbox, without causing a loop. Defining:
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Margin" Value="0,2,0,2" />
:
</Style>
would result in the error: "a loop was detected in the property expression".
The way I chose to get around this was to force named styles everywhere. For example:
<Style x:Key="TextBase" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Margin" Value="0,2,0,2" />
:
</Style>
<Style x:Key="Text25Chars" TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBase}">
<Setter Property="Margin" Value="0,2,0,2" />
:
</Style>
try this:
<TextBox>
<TextBox.Style>
<Style BasedOn="{StaticResource {x:Type TextBox}}">
</Style>
</TextBox.Style>
</TextBox>
edit:
forgot the TargetType, this works for me:
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary Source="/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35,
ProcessorArchitecture=MSIL;component/themes/luna.normalcolor.xaml" />
</Window.Resources>
<TextBox>
<TextBox.Style>
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Foreground" Value="Blue" />
</Style>
</TextBox.Style>
tototototottototo
</TextBox>
</Window>