Чёрное окно WPF
Тупо чёрное окно при запуске приложения, при том что VS XAML designer исправно его отображает, появилaсь проблема просто во время того как я оформлял ScrollBar
. Ошибок тоже нет:
В то же время в Visual Studio:
Пробовал запускать код в другом проекте, результат тот же.
MainWindow.xaml:
<Window x:Class="Alarm.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:Alarm"
mc:Ignorable="d"
Title="Alarm" MinHeight="200" Height="450" MinWidth="300" Width="600" Style="{DynamicResource WindowStyle}">
<Window.Resources>
<SolidColorBrush x:Key="WindowBackground" Color="#162633"/>
<SolidColorBrush x:Key="BoxContentBackground" Color="#274559"/>
<SolidColorBrush x:Key="Primary" Color="#416578"/>
<SolidColorBrush x:Key="PrimaryOver" Color="#4E7C99"/>
<SolidColorBrush x:Key="PrimaryPressed" Color="#30556E"/>
<SolidColorBrush x:Key="PrimarySelected" Color="#30556E"/>
<SolidColorBrush x:Key="ScrollBarBackground" Color="#2E5169"/>
<SolidColorBrush x:Key="PrimaryForeground" Color="#E0E0E0"/>
<SolidColorBrush x:Key="AdditionaryForeground" Color="#9E9E9E"/>
<SolidColorBrush x:Key="SecondaryForeground" Color="#222222"/>
<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="IsTabStop" Value="false" />
<Setter Property="Focusable" Value="false" />
<Setter Property="Width" Value="7"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border CornerRadius="15,5,5,15" Background="{DynamicResource Primary}" BorderThickness="0" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Width" Value="Auto" />
<Setter Property="Height" Value="Auto" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition MaxHeight="0" />
<RowDefinition Height="0.00001*" />
<RowDefinition MaxHeight="0" />
</Grid.RowDefinitions>
<Border Grid.RowSpan="3" CornerRadius="15,5,5,15" Background="{DynamicResource ScrollBarBackground}"/>
<Track x:Name="PART_Track" IsDirectionReversed="True" Grid.Row="1">
<Track.Thumb>
<Thumb Style="{DynamicResource ScrollBarThumb}"/>
</Track.Thumb>
</Track>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="WindowStyle" TargetType="Window">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Background" Value="{DynamicResource WindowBackground}"/>
</Style>
<Style x:Key="ContentBorderStyle" TargetType="Border">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Background" Value="{DynamicResource BoxContentBackground}"/>
<Setter Property="CornerRadius" Value="5,5,3,3"/>
</Style>
<Style x:Key="ContentBorderStyle2" TargetType="Border">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Background" Value="{DynamicResource BoxContentBackground}"/>
<Setter Property="CornerRadius" Value="15,15,15,15"/>
</Style>
<Style x:Key="ContentBorderStyle3" TargetType="Border">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Background" Value="{DynamicResource BoxContentBackground}"/>
<Setter Property="CornerRadius" Value="4,4,0,0"/>
</Style>
<Style x:Key="AlarmsListStyle" BasedOn="{StaticResource {x:Type ToggleButton}}" TargetType="RadioButton">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Background" Value="{DynamicResource Primary}"/>
<Setter Property="Foreground" Value="{DynamicResource PrimaryForeground}"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5,5,3,3"/>
</Style>
</Style.Resources>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource PrimaryOver}"/>
</Trigger>
<Trigger Property="IsMouseCaptured" Value="True">
<Setter Property="Background" Value="{DynamicResource PrimaryPressed}"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="{DynamicResource PrimarySelected}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="DefaultButtonStyle" TargetType="Button">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Background" Value="{DynamicResource Primary}"/>
<Setter Property="Foreground" Value="{DynamicResource PrimaryForeground}"/>
<Setter Property="FontSize" Value="17"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Margin="4"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="3"/>
</Style>
</Style.Resources>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource PrimaryOver}"/>
</Trigger>
<Trigger Property="IsMouseCaptured" Value="True">
<Setter Property="Background" Value="{DynamicResource PrimaryPressed}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="AlarmListTextStyle" TargetType="TextBlock">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="FontSize" Value="23"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontFamily" Value="Fantasy"/>
</Style>
<Style x:Key="AlarmListAdditionStyle" TargetType="TextBlock">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="FontSize" Value="13"/>
<Setter Property="Foreground" Value="{DynamicResource AdditionaryForeground}"/>
</Style>
</Window.Resources>
<Grid Visibility="Visible">
<Grid.RowDefinitions>
<RowDefinition Height="145*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Margin="10,10,10,10" Padding="10,10,5,10" Style="{DynamicResource ContentBorderStyle}">
<ScrollViewer>
<StackPanel Height="800">
<RadioButton HorizontalAlignment="Stretch" Margin="5" GroupName="Group" Style="{DynamicResource AlarmsListStyle}">
<Border HorizontalAlignment="Stretch">
<WrapPanel Orientation="Vertical">
<TextBlock Style="{DynamicResource AlarmListTextStyle}">
<Image />
<Run Text="6:00"/>
</TextBlock>
<TextBlock Text="Example | Example" Style="{DynamicResource AlarmListAdditionStyle}"/>
</WrapPanel>
</Border>
</RadioButton>
</StackPanel>
</ScrollViewer>
</Border>
<Border Grid.Row="1" Style="{DynamicResource ContentBorderStyle3}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Name="editBtn" Content="Edit" Margin="10,10,2.5,10" HorizontalAlignment="Right" Style="{DynamicResource DefaultButtonStyle}"/>
<Button x:Name="selectBtn" Content="Select" Margin="2.5,10,10,10" HorizontalAlignment="Right" Style="{DynamicResource DefaultButtonStyle}"/>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Left">
<Button x:Name="deleteBtn" Content="Delete" Margin="10,10,2.5,10" HorizontalAlignment="Right" Style="{DynamicResource DefaultButtonStyle}"/>
<Button x:Name="createBtn" Content="New" Margin="2.5,10,10,10" HorizontalAlignment="Right" Style="{DynamicResource DefaultButtonStyle}"/>
</StackPanel>
</Grid>
</Border>
</Grid>
Источник: Stack Overflow на русском