I'm creating a custom error box which allows me to store additional information (and other features which aren't relevant). The textbox should be able to scroll to adapt to error messages. However, I believe there is an issue with the height. The contents of the expander go beyond the max height of the window. As a result, the scrollbar is considered not required even though it is off the screen.
How can I get the scrollbar to work as expected?
Error Window:
XML Definition:
<Window x:Class="CustomErrorBox"
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:View"
mc:Ignorable="d"
Title="WpfMessageBox" MinHeight="240"
MinWidth="500" MaxHeight="360" MaxWidth="500"
Background="Transparent"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterScreen"
ShowInTaskbar="False" ResizeMode="NoResize"
WindowStyle="None" Topmost="True">
<Border BorderBrush="LightSlateGray" BorderThickness="0" CornerRadius="0">
<Grid >
<Grid.Resources>
<Style TargetType="Button" x:Key="MessageBoxButtonStyle">
<Setter Property="Background" Value="Transparent" />
<Setter Property="TextBlock.TextAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="Border" CornerRadius="0" BorderBrush="#000" BorderThickness="1,1,1,1" Background="{TemplateBinding Background}">
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}" Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalAlignment}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Row="1" Grid.Column="0" Grid.RowSpan="3" Grid.ColumnSpan="2">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" Opacity="0.8">
<GradientStop Color="#FF7FCFFF" Offset="1"/>
<GradientStop Color="#FFCFFFCF"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
<Rectangle.Fill>
<!-- TODO - Find some nice colours for header bar -->
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" Opacity="0.5">
<GradientStop Color="#26508A" Offset="0.0"/>
<GradientStop Color="#2A739E" Offset="1.0"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Grid Grid.Row="0" Grid.ColumnSpan="2" MinHeight="40" >
<TextBlock Margin="5,1,0,1" Name="MessageTitle" FontWeight="Bold" TextTrimming="CharacterEllipsis" LineHeight="22" FontSize="16" VerticalAlignment="Center" Foreground="White"/>
</Grid>
<Image Name="img" Margin="5" Grid.Row="1" Grid.Column="0" Width="50" Height="50" Stretch="Fill" />
<ScrollViewer Grid.Row="1" Grid.Column="1" VerticalScrollBarVisibility="Auto">
<TextBlock Margin="10,5,10,5" VerticalAlignment="Center" TextWrapping="Wrap" Name="txtMsg" FontSize="14" LineHeight="20" ScrollViewer.VerticalScrollBarVisibility="Auto" />
</ScrollViewer>
<Grid Grid.Row="2" Grid.ColumnSpan="2" Grid.Column="0" >
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
<Button Name="btnOk" Content="OK" Margin="3,5" MinWidth="70" Height="35" Click="Button_Click" Foreground="Black" FontSize="14" Style="{StaticResource MessageBoxButtonStyle}"
Background="#b6dbd6" VerticalAlignment="Center" HorizontalAlignment="Stretch" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" />
<Button Name="btnYes" Content="Yes" Margin="3,5" MinWidth="70" Height="35" Click="Button_Click" Foreground="Black" FontSize="14" Style="{StaticResource MessageBoxButtonStyle}"
Background="#b6dbd6" VerticalAlignment="Center" HorizontalAlignment="Stretch" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
<Button Name="btnNo" Content="No" Margin="3,5" MinWidth="70" Height="35" Click="Button_Click" Foreground="Black" FontSize="14" Style="{StaticResource MessageBoxButtonStyle}"
Background="#dbb6b6" VerticalAlignment="Center" HorizontalAlignment="Stretch" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" />
<Button Name="btnCancel" Margin="3,5" Content="Cancel" MinWidth="70" Height="35" Click="Button_Click" Style="{StaticResource MessageBoxButtonStyle}" Foreground="Black"
Background="#dbb6b6" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Stretch" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
</StackPanel>
</Grid>
<Expander Header="Further Information" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Margin="5">
<ScrollViewer>
<StackPanel Orientation="Vertical" Height="Auto">
<TextBlock Margin="10,5,10,5" Name="ExpanderMessage" TextWrapping="Wrap" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
<Button Content="Copy to Clipboard" HorizontalAlignment="Right" Margin="5"/>
</StackPanel>
</ScrollViewer>
</Expander>
</Grid>
</Border>
</Window>
The last RowDefinition in your RowDefinitions needs to be changed:
Try this. Make your last rowDef as *:
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
Related
When I try to display content from the ContentPresenter I cannot see anything. The test block does not display any text and it seems to be hidden.
<local:ResizableVideoHostWindow x:Class="TestClass"
x:ClassModifier="internal"
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:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
mc:Ignorable="d"
Title="{Binding Title}">
<Window.Style>
<Style TargetType="{x:Type local:ResizableVideoHostWindow}">
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome
CaptionHeight="30"
CornerRadius="1"
GlassFrameThickness="0,0,0,-1"
NonClientFrameEdges="None"
ResizeBorderThickness="5"
UseAeroCaptionButtons="true"/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ResizableVideoHostWindow}">
<Grid x:Name="AppTitleBar" Background="Transparent" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>
<ColumnDefinition/>
<ColumnDefinition x:Name="RightPaddingColumn" Width="0"/>
</Grid.ColumnDefinitions>
<Button
Background="Transparent"
Visibility="Visible"
BorderThickness="0"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Width="20"
Height="20"
Margin="8,2,0,0"
shell:WindowChrome.IsHitTestVisibleInChrome="True">
<TextBlock Text="" FontFamily="Segoe MDL2 Assets">
</TextBlock>
</Button>
<TextBlock
FontFamily="Segoe UI"
Grid.Column="1"
Height="20"
HorizontalAlignment="Left"
VerticalAlignment="Center"
TextAlignment="Center"
Margin="35,4,0,0"
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" />
<Button
Background="Transparent"
Visibility="Visible"
BorderThickness="0"
Grid.Column="1"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Margin="0,0,160,0"
Width="30"
Height="30"
shell:WindowChrome.IsHitTestVisibleInChrome="True">
<TextBlock Text="" FontFamily="Segoe MDL2 Assets">
</TextBlock>
</Button>
<ContentPresenter Grid.Row="1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="WindowState" Value="Maximized">
<Setter Property="BorderThickness" Value="7" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Style>
<Grid Visibility="Visible">
<TextBlock Text="Test Block" FontSize="20" >
</TextBlock>
<local:AppProxyContainer
DataContext="{Binding ContainerViewModel}" />
</Grid>
</local:ResizableVideoHostWindow>
I am mainly confused on how to display the content. I have seen other posts stating that this method of using ContentPresenter works, but it does not work for me.
You use the ContentPresenter correctly, but you do not set its column in the Grid, so it will be placed in the LeftPaddingColumn column, which has zero Width.
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>
<ColumnDefinition/>
<ColumnDefinition x:Name="RightPaddingColumn" Width="0"/>
</Grid.ColumnDefinitions>
Set its attached Grid.Column property to 1, so it will be displayed in the second column, which sizes to the remaining space.
<ContentPresenter Grid.Row="1" Grid.Column="1"/>
I have a round-cornered border and I am trying to make its contents to be also round-cornered but my attempts are not working. Basically I am doing a kind of custom MessageBox but simpler, only with one image icon, a text and a button. No title bar. Image icon is changing depending on the type of message.
Stackpanel corners overlaps over border so border corners are not showing rounded.
ATTEMPT #1:
<Border x:Name="MyCustomMessageBox"
CornerRadius="5,5,5,5"
Grid.ZIndex="3"
Visibility="{Binding IsMessageBoxShown, Mode=TwoWay, Converter={StaticResource BoolToVis}}"
Width="auto" Height="auto"
HorizontalAlignment="Center"
VerticalAlignment="Center"
BorderBrush="DarkBlue" BorderThickness="1"
Background="White">
<Border.Effect>
<DropShadowEffect />
</Border.Effect>
<Grid Background="Blue">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" Background="WhiteSmoke">
<Grid>
<Image VerticalAlignment="Center" HorizontalAlignment="Left"
Source="/Common.MyImages;component/Images/Info.png"
Height="48" Width="48" Margin="20,10">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="/Common.MyImages;component/Images/Info.png"/>
<Style.Triggers>
<DataTrigger Binding="{Binding MsgType}" Value="1">
<Setter Property="Source" Value="/Common.MyImages;component/Images/Error.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</Grid>
<TextBlock Width="280" Margin="0,0,10,0" VerticalAlignment="Center" HorizontalAlignment="Left"
Background="Transparent" FontSize="12" TextWrapping="Wrap"><Run Text="This is a message"/>
</TextBlock>
</StackPanel>
<Button x:Name="btnCustomMessageBox" Grid.Row="1" Grid.Column="0"
Click="btnCustomMessageBox_Click"
HorizontalAlignment="Center" Margin="10" Width="80" Content="Ok" Visibility="Visible"/>
</Grid>
</Border>
ATTEMPT #2:
As explained here, I have tried also but without success.
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=MyCustomMessageBox}" />
</Grid.OpacityMask>
<!-- Here goes all the above border code -->
</Grid>
The following should solve your issue.
<Border x:Name="MyCustomMessageBox"
CornerRadius="5"
Visibility="{Binding IsMessageBoxShown, Mode=TwoWay, Converter={StaticResource BoolToVis}}"
Width="auto" Height="auto"
HorizontalAlignment="Center"
VerticalAlignment="Center"
BorderBrush="DarkBlue"
BorderThickness="1"
Background="blue">
<Border.Effect>
<DropShadowEffect />
</Border.Effect>
<Grid> <!-- removed the Background here. Only letting borders provide background. -->
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--
Added a border to fill the top part of the grid with the
whitesmoke color using a borderradius on the top.
Also note that the Background from the stackpanel was removed.
-->
<Border
Grid.Row="0" Grid.Column="0"
Name="mask"
Background="WhiteSmoke"
CornerRadius="5,5,0,0"
/>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
<Grid>
<Image VerticalAlignment="Center" HorizontalAlignment="Left"
Source="/Common.MyImages;component/Images/Info.png"
Height="48" Width="48" Margin="20,10">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="/Common.MyImages;component/Images/Info.png"/>
<Style.Triggers>
<DataTrigger Binding="{Binding MsgType}" Value="1">
<Setter Property="Source" Value="/Common.MyImages;component/Images/Error.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</Grid>
<TextBlock Width="280" Margin="0,0,10,0" VerticalAlignment="Center" HorizontalAlignment="Left"
Background="Transparent" FontSize="12" TextWrapping="Wrap"><Run Text="This is a message"/>
</TextBlock>
</StackPanel>
<Button x:Name="btnCustomMessageBox" Grid.Row="1" Grid.Column="0"
Click="btnCustomMessageBox_Click"
HorizontalAlignment="Center" Margin="10" Width="80" Content="Ok" Visibility="Visible"/>
</Grid>
</Border>
I have a simple TreeView, I'm not able to navigate in the TextBox with the focus. Do you have any suggestions???
I have updated the xaml code for give you more details. I hope this is helpful.
More Detail.
More Detail.
More Detail.
More Detail.
More Detail.
<StackPanel Orientation="Vertical" Margin="5">
<StackPanel Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="Column1"/>
<ColumnDefinition Width="5" SharedSizeGroup="Column2"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
</Grid.RowDefinitions>
<GridSplitter Grid.Column="1" Grid.RowSpan="2147483647" HorizontalAlignment="Left" Width="5" VerticalContentAlignment="Stretch" IsTabStop="False"/>
<TextBlock Name="Number" Grid.Row="0" Grid.Column="0" Text="Number"/>
<TextBox x:Name="TxtNumber" Grid.Row="0" Grid.Column="2" Text="{Binding Number}" TabIndex="0"/>
<TextBlock Name="Name" Grid.Row="1" Grid.Column="0" Text="Name"/>
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding Name}" TabIndex="1"/>
</Grid>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="MyTree"/>
<TreeView x:Name="MyTree" BorderThickness="0" Grid.IsSharedSizeScope="True" KeyboardNavigation.TabNavigation="Continue">
<TreeView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Black" />
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
</Style>
</TreeView.ItemContainerStyle>
<TreeViewItem>
<TreeViewItem.Header>
<TextBlock Text="First Block" FontWeight="Bold"/>
</TreeViewItem.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="Column1"/>
<ColumnDefinition Width="5" SharedSizeGroup="Column2"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
</Grid.RowDefinitions>
<GridSplitter Grid.Column="1" Grid.RowSpan="4" Width="5" HorizontalAlignment="Left" VerticalContentAlignment="Stretch" IsTabStop="False"/>
<TextBlock Grid.Row="0" Grid.Column="0" Text="A"/>
<CheckBox Grid.Row="0" Grid.Column="2" IsChecked="{Binding A}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="B"/>
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding B}" Width="200"/>
<TextBlock Name="PassBin" Grid.Row="2" Grid.Column="0" Text="C"/>
<ComboBox x:Name="CbxPassBin" Grid.Row="2" Grid.Column="2" ItemsSource="{Binding C}" SelectedValue="{Binding SelectedC}"/>
</Grid>
</TreeViewItem>
</TreeView>
</StackPanel>
</StackPanel>
TabIndex should be 1 and Focusable="true"
I found a solution, at least for my specific situation. The error was the ItemContainerStyle definition in the TreeView. Define the Window/UserControl resource's style for the TreeViewItem as below:
<Style TargetType="TreeViewItem">
<Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
<Setter Property="IsTabStop" Value="False"/>
</Style>
this below is a chat window. the font size is not setup where to put this? for the chat text we do have font size for the send button
MinHeight="550" MinWidth="834"
Closed="Window_Closed" >
<Window.Resources>
<Style x:Key="SpeechOptionsStyle" TargetType="RadioButton">
<Setter Property="Margin" Value="2,8,0,0" />
</Style>
<Style x:Key="ChatButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="23" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Width" Value="150" />
<Setter Property="Margin" Value="0,5,0,0" />
</Style>
</Window.Resources>
<Grid>
<Grid.Background>
<LinearGradientBrush>
<GradientStop Color="LightSlateGray" Offset="0"/>
<GradientStop Color="Gainsboro" Offset="0.7"/>
<GradientStop Color="LightSlateGray" Offset="0.95"/>
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="170" />
</Grid.ColumnDefinitions>
<ListBox Grid.Row="1" Grid.Column="0" x:Name="chatListBoxMsgs" Margin="10"
HorizontalContentAlignment="Stretch" >
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" >
<EventSetter Event="MouseDoubleClick"
Handler="chatListBoxMsgs_MouseDoubleClick" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Grid Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Margin="10"
Width="150">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox Grid.Row="0" x:Name="chatListBoxNames" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="150" />
<StackPanel Grid.Row="1" Margin="0,10,0,0"> <CheckBox Visibility="Hidden" x:Name="chatCheckBoxWhisper" Height="17" HorizontalAlignment="Left" Foreground="Black" FontSize="12" >Whisper Mode</CheckBox>
</StackPanel>
</Grid>
<TextBlock Visibility="Visible" Grid.Row="2" Grid.Column="0" x:Name="chatLabelWritingMsg"
Height="45" VerticalAlignment="Top" Foreground="MediumBlue"
TextWrapping="Wrap" Margin="10,0,0,0">Status</TextBlock>
<StackPanel Grid.Row="2" Grid.Column="1" Grid.RowSpan="2"
Orientation="Vertical" Margin="10,0" >
<Button x:Name="chatButtonConnect" Click="chatButtonConnect_Click"
Style="{StaticResource ChatButtonStyle}" >Connect</Button>
<Button x:Name="chatButtonDisconnect" Click="chatButtonDisconnect_Click"
Style="{StaticResource ChatButtonStyle}" >Disconnect</Button>
</StackPanel>
<Grid Grid.Row="3" Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" x:Name="chatTxtBoxType" Height="60"
VerticalAlignment="Top" Margin="10,0,5,5" TextWrapping="Wrap"
SpellCheck.IsEnabled="True" />
<Button Grid.Column="1" x:Name="chatButtonSend"
Click="chatButtonSend_Click" Height="60" VerticalAlignment="Top"
HorizontalAlignment="Right" Width="50" Margin="5,0,5,5"
FontSize="14">Send</Button>
</Grid>
</Grid>
</Window>
we have here the fontsize for the send button where do we put font ssize for the chat text it is defaulting to 8
From your code I think you want to set the font size of chatTxtBoxType. You can do it right in there (using an example size of 14):
<TextBox Grid.Column="0" x:Name="chatTxtBoxType" Height="60"
VerticalAlignment="Top" Margin="10,0,5,5" TextWrapping="Wrap"
SpellCheck.IsEnabled="True" FontSize="14"/>
Or using a style, like how you did for buttons (in that case, you might want to move some other properties to the style):
<Window.Resources>
<Style x:Key="ChatBoxStyle" TargetType="TextBox">
<Setter Property="FontSize" Value="14" />
</Style>
...
<TextBox Grid.Column="0" x:Name="chatTxtBoxType" Height="60"
VerticalAlignment="Top" Margin="10,0,5,5" TextWrapping="Wrap"
SpellCheck.IsEnabled="True" Style="{StaticResource ChatBoxStyle}"/>
I have strange behaviour of my application. I display nine buttons in window but sometimes one or two buttons disappear. It isn't regular. Sometimes button contain one part(small rectangle or content).
App.xaml
<Application.Resources>
<Style TargetType="{x:Type Button}" x:Key="BiletButton1a">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle Fill="{TemplateBinding Background}">
<Rectangle.Effect>
<DropShadowEffect ShadowDepth="5" Color="Gray" Opacity="0.5"/>
</Rectangle.Effect>
</Rectangle>
<Rectangle Fill="#E23817" HorizontalAlignment="Right" Height="133" Width="18"/>
<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Button}" x:Key="BiletButton1b">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle Fill="{TemplateBinding Background}">
<Rectangle.Effect>
<DropShadowEffect ShadowDepth="5" Color="Gray" Opacity="0.5"/>
</Rectangle.Effect>
</Rectangle>
<Rectangle Fill="#E23817" HorizontalAlignment="Right" VerticalAlignment="Top" Height="67" Width="18"/>
<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Button}" x:Key="BiletButton2a">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle Fill="{TemplateBinding Background}">
<Rectangle.Effect>
<DropShadowEffect ShadowDepth="5" Color="Gray" Opacity="0.5"/>
</Rectangle.Effect>
</Rectangle>
<Rectangle Fill="#239AD4" HorizontalAlignment="Right" Height="133" Width="18"/>
<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Button}" x:Key="BiletButton2b">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle Fill="{TemplateBinding Background}">
<Rectangle.Effect>
<DropShadowEffect ShadowDepth="5" Color="Gray" Opacity="0.5"/>
</Rectangle.Effect>
</Rectangle>
<Rectangle Fill="#239AD4" HorizontalAlignment="Right" VerticalAlignment="Top" Height="67" Width="18"/>
<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
Window1.xaml
<Button Style="{StaticResource BiletButton1a}" FontSize="30" HorizontalAlignment="Left" Margin="16,328,0,0" x:Name="button_ticket1a" Height="130" Width="226" Click="button_ticket1a_Click" VerticalAlignment="Top">
<Grid >
<TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Stretch" Name="tblock1a" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>
</Grid>
</Button>
<Button Style="{StaticResource BiletButton1b}" FontSize="30" HorizontalAlignment="Left" Margin="16,492,0,0" x:Name="button_ticket1b" Height="130" Width="226" Click="button_ticket1b_Click" VerticalAlignment="Top">
<Grid >
<TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock1b" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>
</Grid>
</Button>
<Button Style="{StaticResource BiletButton2a}" FontSize="30" HorizontalAlignment="Left" Margin="267,330,0,0" x:Name="button_ticket2a" Height="130" Width="226" Click="button_ticket2a_Click" VerticalAlignment="Top">
<Grid >
<TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Stretch" Name="tblock2a" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>
</Grid>
</Button>
<Button Style="{StaticResource BiletButton2b}" FontSize="30" HorizontalAlignment="Left" Margin="267,492,0,0" x:Name="button_ticket2b" Height="130" Width="226" Click="button_ticket2b_Click" VerticalAlignment="Top">
<Grid >
<TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock2b" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>
</Grid>
</Button>
<Button Style="{StaticResource BiletButton2a}" FontSize="30" HorizontalAlignment="Left" Margin="521,330,0,0" x:Name="button_ticket3a" Height="130" Width="226" Click="button_ticket3a_Click" VerticalAlignment="Top">
<Grid >
<TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Stretch" Name="tblock3a" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>
</Grid>
</Button>
<Button Style="{StaticResource BiletButton2b}" FontSize="30" HorizontalAlignment="Left" Margin="521,492,0,0" x:Name="button_ticket3b" Height="130" Width="226" Click="button_ticket3b_Click" VerticalAlignment="Top">
<Grid >
<TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock3b" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>
</Grid>
</Button>
<Button Style="{StaticResource BiletButton2b}" FontSize="30" HorizontalAlignment="Left" Margin="267,654,0,0" x:Name="button_ticket2c" Height="130" Width="226" Click="button_ticket2c_Click" VerticalAlignment="Top">
<Grid >
<TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock2c" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>
</Grid>
</Button>
<Button Style="{StaticResource BiletButton2b}" FontSize="30" HorizontalAlignment="Left" Margin="521,654,0,0" x:Name="button_ticket3c" Height="130" Width="226" Click="button_ticket3c_Click" VerticalAlignment="Top">
<Grid >
<TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock3c" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>
</Grid>
</Button>
<Button Style="{StaticResource BiletButton1b}" FontSize="30" HorizontalAlignment="Left" Margin="16,654,0,0" x:Name="button_ticket1c" Height="130" Width="226" Click="button_ticket1c_Click" VerticalAlignment="Top">
<Grid >
<TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock1c" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>
</Grid>
</Button>
</Grid>