wpf streamResourceinfo为null

时间:2015-05-25 14:46:18

标签: wpf nullpointerexception stream

我有一个问题:我正在运行wpf和按钮设计我的代码

private void Main_Page_Loaded(object sender, RoutedEventArgs e)
{
    if (!Utils.IsInDesignerMode)
    {

        Uri resourceUri = new Uri("Images\\aaa.png", UriKind.Relative);
        StreamResourceInfo streamInfo = Application.GetResourceStream(resourceUri);

        BitmapFrame temp = BitmapFrame.Create(streamInfo.Stream);
        var brush = new ImageBrush();
        brush.ImageSource = temp;

        button.Background = brush;
    }

}

public class Utils
{
    public static bool IsInDesignerMode
    {
        get
        {
            return ((bool)(DesignerProperties.IsInDesignModeProperty
                .GetMetadata(typeof(DependencyObject)).DefaultValue));
        }
    }
}

但是streaminfo是nulL和xaml代码

和app xaml是

<Application
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:sunum_wpf" x:Class="sunum_wpf.App"
             StartupUri="MainWindow.xaml">
    <Application.MainWindow>
        <local:MainWindow/>
    </Application.MainWindow>
</Application>


<Window
        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:RuntimeBinder="clr-namespace:Microsoft.CSharp.RuntimeBinder;assembly=Microsoft.CSharp" xmlns:ee="http://schemas.microsoft.com/expression/2010/effects" mc:Ignorable="d" x:Class="sunum_wpf.MainWindow"
        Title="MainWindow" Height="350" Width="525" d:DataContext="{d:DesignInstance {x:Type RuntimeBinder:CSharpArgumentInfoFlags}}">
    <Window.Resources>
        <Storyboard x:Key="Animation">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="btn_ana_sayfa">
                <EasingDoubleKeyFrame KeyTime="0" Value="400.889"/>
                <EasingDoubleKeyFrame KeyTime="0:0:2.4" Value="1.778"/>
            </DoubleAnimationUsingKeyFrames>

    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource Animation}"/>
            <BeginStoryboard Storyboard="{StaticResource Anim2}"/>
        </EventTrigger>
    </Window.Triggers>
    <Grid x:Name="Main_Page" Background="#FFA5BDBE" Margin="0,0,0,5" Loaded="Main_Page_Loaded">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="53*"/>
            <ColumnDefinition Width="34*"/>
            <ColumnDefinition Width="172*"/>
        </Grid.ColumnDefinitions>
        <Grid.Effect>
            <ee:BloomEffect BloomIntensity="1.3" BaseSaturation="1" BaseIntensity="1" BloomSaturation="1.2" Threshold="0.5"/>
        </Grid.Effect>
        <Button x:Name="btn_Duyuru" Content="Duyurular" HorizontalAlignment="Left" Margin="10,75,0,0" VerticalAlignment="Top" Width="100" Background="#FFE5D7D7" RenderTransformOrigin="4.936,0.512" Click="btn_Duyuru_Click" Grid.ColumnSpan="2">
            <Button.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Button.RenderTransform>
        </Button>

        <Button x:Name="button" Content="İletişim" HorizontalAlignment="Left" Margin="10,262,0,0" VerticalAlignment="Top" Width="100" Background="#FFE3C7C7" RenderTransformOrigin="0.5,0.5" Click="button_Click" Grid.ColumnSpan="2">
            <Button.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Button.RenderTransform>
        </Button>
        <Button x:Name="Button1" Width="200" Height="200" Content="Button1" Margin="0,0,0,400">
            <Button.Background>
                <ImageBrush ImageSource ="C:\Users\Ramazan\Documents\Visual Studio 2013\Projects\sunum_wpf\sunum_wpf\Images\indir.jpg"></ImageBrush>
            </Button.Background>
        </Button>

    </Grid>
</Window>

请你帮帮我吗?

我将抛​​出异常对象引用未设置为对象的实例。

祝福

0 个答案:

没有答案