Wpf按钮内容未显示特定按钮

时间:2017-08-01 14:30:21

标签: c# wpf visual-studio xaml imagebutton

我的程序显示两个实时视频输入,并具有分别旋转,翻转和反转每个输入的按钮。每组按钮都位于Feed上方的堆栈面板中。我的XAML引用了一些我用作图标的png图像,每个按钮的content属性都是图像。

我首先创建了一个面板,它们都按照我的意图运行,但是在将XAML复制到另一组按钮后,新的集合可以工作,而带有未更改代码的旧集合不再具有图标:

Buttons on left have icon missing

最后的反转按钮正常工作,但它是ToggleButton而不是Button

有什么问题?

MainWindow.xaml:

<Window x:Class="MLD_UI_1.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:MLD_UI_1" Loaded="Window_Loaded"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" MinHeight="700" Width="525" MinWidth="1050">
    <Grid Background="{StaticResource MainBackgroundBrush}">

        <Grid.RowDefinitions>
            <RowDefinition Height="10"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="*" MinHeight="80"/>
            <RowDefinition Height="200"/>
            <RowDefinition Height="10"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10"/>
            <ColumnDefinition Width="*" MinWidth="100"/>
            <ColumnDefinition Width="*" MinWidth="100"/>
            <ColumnDefinition Width="10"/>
        </Grid.ColumnDefinitions>

        <Border BorderThickness="2 2 1 2"
                BorderBrush="Black"
                Grid.Column="1" Grid.Row="1"
                Background="{StaticResource UvGradientBrush}"
                CornerRadius="5 0 0 5"/>
        <Border BorderThickness="1 2 2 2"
                BorderBrush="Black"
                Grid.Column="2" Grid.Row="1"
                Background="{StaticResource IrGradientBrush}"
                CornerRadius="0 5 5 0"/>

        <Border BorderThickness="2 2 1 2"
                BorderBrush="Black"
                Grid.Column="1" Grid.Row="3"
                Background="{StaticResource GradientBrush}"
                CornerRadius="5 0 0 5">
        </Border>
        <Border BorderThickness="1 2 2 2"
                BorderBrush="Black"
                Grid.Column="2" Grid.Row="3"
                Background="{StaticResource GradientBrush}"
                CornerRadius="0 5 5 0"/>

        <StackPanel Grid.Column="1" Grid.Row="1"
                    Orientation="Horizontal"
                    Margin="10 0 10 0">
            <TextBlock Text="UV"
                       FontFamily="Tahoma"
                       Foreground="White"
                       VerticalAlignment="Center"
                       FontSize="20"/>
            <Button x:Name="AnticlockwiseBtn"
                    Style="{StaticResource ButtonStyle}"
                    Content="{StaticResource ARotateImg}"
                    Height="15"
                    Width="15"
                    Click="AnticlockwiseBtn_Click"/>
            <Button x:Name="ClockwiseBtn"
                    Style="{StaticResource ButtonStyle}"
                    Content="{StaticResource RotateImg}"
                    Height="15"
                    Width="15"
                    Click="ClockwiseBtn_Click"/>
            <Button x:Name="HorizontalBtn"
                    Style="{StaticResource ButtonStyle}"
                    Content="{StaticResource HFlipImg}"
                    Height="15"
                    Width="15"
                    Click="HorizontalBtn_Click"/>
            <Button x:Name="VerticalBtn"
                    Style="{StaticResource ButtonStyle}"
                    Content="{StaticResource VFlipImg}"
                    Height="15"
                    Width="15"
                    Click="VerticalBtn_Click"/>
            <ToggleButton x:Name="InvertBtn"
                    Style="{StaticResource ToggleButtonStyle}"
                    Height="15"
                    Width="15"
                    Click="InvertBtn_Click"/>
        </StackPanel>

        <StackPanel Grid.Column="2" Grid.Row="1"
                    Orientation="Horizontal"
                    Margin="10 0 10 0">
            <TextBlock Text="IR"
                       FontFamily="Tahoma"
                       Foreground="White"
                       VerticalAlignment="Center"
                       FontSize="20"/>
            <Button x:Name="AnticlockwiseBtnR"
                    Style="{StaticResource ButtonStyle}"
                    Content="{StaticResource ARotateImg}"
                    Height="15"
                    Width="15"
                    Click="AnticlockwiseBtnR_Click"/>
            <Button x:Name="ClockwiseBtnR"
                    Style="{StaticResource ButtonStyle}"
                    Content="{StaticResource RotateImg}"
                    Height="15"
                    Width="15"
                    Click="ClockwiseBtnR_Click"/>
            <Button x:Name="HorizontalBtnR"
                    Style="{StaticResource ButtonStyle}"
                    Content="{StaticResource HFlipImg}"
                    Height="15"
                    Width="15"
                    Click="HorizontalBtnR_Click"/>
            <Button x:Name="VerticalBtnR"
                    Style="{StaticResource ButtonStyle}"
                    Content="{StaticResource VFlipImg}"
                    Height="15"
                    Width="15"
                    Click="VerticalBtnR_Click"/>
            <ToggleButton x:Name="InvertBtnR"
                    Style="{StaticResource ToggleButtonStyle}"
                    Height="15"
                    Width="15"
                    Click="InvertBtnR_Click"/>
        </StackPanel>

        <Image x:Name="imagePane1"
               Grid.Column="1" Grid.Row="2"
               HorizontalAlignment="Stretch"
               VerticalAlignment="Stretch"
               Margin="2 2 2 2"/>
        <Image x:Name="imagePane2"
               Grid.Column="2" Grid.Row="2"
               HorizontalAlignment="Stretch"
               VerticalAlignment="Stretch"
               Margin="2 2 2 2"/>

        <StackPanel Grid.Column="1"
                    Grid.Row="3"
                    Orientation="Vertical">

            <StackPanel Orientation="Horizontal" Height="40">

            </StackPanel>

            <StackPanel Orientation="Horizontal" Height="40">

            </StackPanel>

            <StackPanel Orientation="Horizontal" Height="40">

            </StackPanel>

            <StackPanel Orientation="Horizontal" Height="40">

            </StackPanel>

            <StackPanel Orientation="Horizontal" Height="40">

            </StackPanel>

        </StackPanel>
    </Grid>
</Window>

的App.xaml:

<Application x:Class="MLD_UI_1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:MLD_UI_1"
             StartupUri="MainWindow.xaml"
             Startup="Application_Startup">
    <Application.Resources>
        <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:MLD_UI_1">
            <!--  Define the basic colours  -->
            <Color x:Key="FandFMainColour">#FF228B22</Color>
            <Color x:Key="FandFSecondaryColour">#FF315531</Color>
            <Color x:Key="FandFGrey">#FF696969</Color>
            <Color x:Key="FandFWhite">#FFFFFFFF</Color>
            <Color x:Key="FandFBlack">#FF000000</Color>
            <!--  Define the basic brushes that use the colours  -->
            <SolidColorBrush x:Key="FandFBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="{StaticResource FandFMainColour}" />
            <SolidColorBrush x:Key="HyperlinkBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="#FF0023BF" />
            <SolidColorBrush x:Key="LightBackgroundBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="#FFFFFFE1" />
            <SolidColorBrush x:Key="MainBackgroundBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="{StaticResource FandFGrey}" />
            <SolidColorBrush x:Key="BorderHighlightBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="#FFFF0000" />
            <SolidColorBrush x:Key="SecondaryBorderHighlightBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="#FFFFFF00" />
            <SolidColorBrush x:Key="ForegroundBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="#FF000000" />
            <SolidColorBrush x:Key="TertiaryBackgroundBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="#FFFFFFFF" />
            <SolidColorBrush x:Key="SecondaryBackgroundBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="#FFD3D3D3" />
            <SolidColorBrush x:Key="TransparentBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="Transparent" />
            <SolidColorBrush x:Key="BrighterFandFBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="Lime" />
            <SolidColorBrush x:Key="OrangeBrush"
                     RenderOptions.CachingHint="Cache"
                     RenderOptions.EdgeMode="Aliased"
                     Color="#FFFF8000" />
            <!--  Define a basic gradient that goes from the light green to the dark green  -->
            <LinearGradientBrush x:Key="GradientBrush"
                                 StartPoint="0.5,0"
                                 EndPoint="0.5,1">
                <GradientStop Offset="0"
                      Color="{StaticResource FandFMainColour}" />
                <GradientStop Offset="1"
                      Color="{StaticResource FandFSecondaryColour}" />
            </LinearGradientBrush>
            <!--  Gradient brush for UV toolbar background  -->
            <LinearGradientBrush x:Key="UvGradientBrush"
                         StartPoint="0.5,0"
                         EndPoint="0.5,1">
                <GradientStop Offset="0"
                      Color="#7f4dff" />
                <GradientStop Offset="1"
                      Color="#240080" />
            </LinearGradientBrush>
            <!--  Gradient brush for IR toolbar background  -->
            <LinearGradientBrush x:Key="IrGradientBrush"
                         StartPoint="0.5,0"
                         EndPoint="0.5,1">
                <GradientStop Offset="0"
                      Color="#db2424" />
                <GradientStop Offset="1"
                      Color="#420b0b" />
            </LinearGradientBrush>
            <!--  The global font settings  -->
            <FontFamily x:Key="NormalFontFamily">Verdana</FontFamily>
            <FontFamily x:Key="HeaderFontFamily">Tahoma</FontFamily>
            <!--  Define the basic geometries  -->
            <Geometry x:Key="DownArrowGeometry">M 0 0 L 4 4 L 8 0 Z</Geometry>
            <Geometry x:Key="TickShapeGeometry">M 2,4 C 2,4 3,5 5,13 C 5,13 5,3 12,0</Geometry>
            <Geometry x:Key="ExpanderArrowGeometry">M 1,1.5 L 4.5,5 8,1.5</Geometry>
            <!--  A style for all tool tips  -->
            <Style TargetType="{x:Type ToolTip}">
                <Setter Property="Background"
                Value="{StaticResource GradientBrush}" />
                <Setter Property="BorderBrush"
                Value="{StaticResource ForegroundBrush}" />
                <Setter Property="BorderThickness"
                Value="2" />
                <Setter Property="Foreground"
                Value="{StaticResource LightBackgroundBrush}" />
                <Setter Property="MaxWidth"
                Value="600" />
                <Setter Property="Placement"
                Value="Mouse" />
                <Setter Property="UseLayoutRounding"
                Value="True" />
            </Style>
            <!-- A style for all buttons -->
            <Style TargetType="Button"
                   x:Key="ButtonStyle">
                <Setter Property="Background"
                        Value="{StaticResource LightBackgroundBrush}"/>
                <Setter Property="Foreground"
                        Value="Black"/>
                <Setter Property="FontFamily"
                        Value="Verdana"/>
                <Setter Property="FontSize"
                        Value="12"/>
                <Setter Property="Height"
                        Value="20"/>
                <Setter Property="Margin"
                        Value="10 0 0 0"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Border Background="{TemplateBinding Background}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver"
                             Value="True">
                        <Setter Property="Background"
                                Value="LightGray"/>
                    </Trigger>
                    <Trigger Property="IsPressed"
                             Value="True">
                        <Setter Property="Background"
                                Value="Gray"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
            <!-- Style for ToggleButtons -->
            <Style TargetType="ToggleButton"
                   x:Key="ToggleButtonStyle">
                <Setter Property="Background"
                        Value="{StaticResource LightBackgroundBrush}"/>
                <Setter Property="Foreground"
                        Value="Black"/>
                <Setter Property="Height"
                        Value="20"/>
                <Setter Property="Margin"
                        Value="10 0 0 0"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ToggleButton}">
                            <Border Background="{TemplateBinding Background}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver"
                             Value="True">
                        <Setter Property="Background"
                                Value="HotPink"/>
                    </Trigger>
                    <Trigger Property="IsPressed"
                             Value="True">
                        <Setter Property="Background"
                                Value="Gray"/>
                    </Trigger>
                    <Trigger Property="IsChecked"
                             Value="True">
                        <Setter Property="Background"
                                Value="LightGray"/>
                        <Setter Property="Content"
                                Value="{StaticResource InvImg2}"/>
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <Image Source="images/inverted.png"/>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsChecked"
                             Value="False">
                        <Setter Property="Background"
                                Value="{StaticResource LightBackgroundBrush}"/>
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <Image Source="images/invert.png"/>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
            <!-- Load button icons as resources -->
            <Image x:Key="HFlipImg" Source="images/horizontal flip.png"/>
            <Image x:Key="VFlipImg" Source="images/vertical flip.png"/>
            <Image x:Key="RotateImg" Source="images/clockwise rotate.png"/>
            <Image x:Key="ARotateImg" Source="images/anticlockwise rotate.png"/>
            <Image x:Key="InvImg" Source="images/invert.png"/>
            <Image x:Key="InvImg2" Source="images/inverted.png"/>
        </ResourceDictionary>
    </Application.Resources>
</Application>

0 个答案:

没有答案